@hackage linearbase0.4.0
Standard library for linear types.
Categories
License
MIT
Maintainer
arnaud.spiwack@tweag.io
Links
Versions
Installation
Dependencies (10)
 base >=4.16 && <5
 containers
 ghcprim
 primitive
 text
 transformers Show all…
Dependents (5)
@hackage/referencecounting, @hackage/inlinejava, @hackage/oneliner, @hackage/jni, @hackage/jvm
Linear base
Linear base is a standard library for developing applications with linear
types. It is named linearbase
to be an analog to the original base
package that ships with GHC.
The purpose of linearbase
is to provide the minimal facilities you need to
write practical Linear Haskell code, i.e., Haskell code that uses the
XLinearTypes
language extension.
Motivation
Why do you need linearbase
to write linear projects?

Data types, functions and classes in
base
are not linear types aware. For instance, ifn
is a linearlyboundInt
, the RHS of a definition cannot writen + 1
— this will not type check. We need linear variants ofNum
,Functor
s,Monad
s,($)
, etc. 
This library exports new abstractions that leverage linear types for resource safety or performance. For example, there are new APIs for file and socket I/O as well as for safe inplace mutation of arrays.
Getting started
XLinearTypes
is released with GHC 9, and linearbase
is released
on Hackage and Stackage.
All source files with linear types need a language extension pragma at the top:
{# LANGUAGE LinearTypes #}
User Guide
If you already know what XLinearTypes
does and what the linear
arrow a %1> b
means, then read the User Guide and explore the
examples/
folder to know how to use linearbase
.
You can also find a table comparing base
and linearbase
typeclasses
here.
Learning about XLinearTypes
If you're a Haskeller who hasn't written any Linear Haskell code, don't fear! There are plenty of excellent resources and examples to help you.
Tutorials and examples
 See the
examples/
folder.  Linear examples on watertight 3D models
Reading material
 There is a wiki page.
 Key Blog posts
 Predictable performance (the first blog post from Tweag on this)
 IO State Transitions
 Streaming
 See here for all of Tweag's blog posts on linear types.
 Here is the paper behind
XLinearTypes
.
Talks
–
 Distributed Programming with Linear Types – Haskell Exchange 2017
 Practical Linearity in a higherorder polymorphic language – POPL 2018
 Practical Linearity in a higherorder polymorphic language – Curry on 2018
 Practical Linearity in a higherorder polymorphic language – Haskell Exchange 2018
 Implementing Linear Haskell
 Inplace array update with linear types – ZuriHac 2020
 Typecheck Your Memory Management with Linear Types – Haskell Exchange 2017
Contributing
Linear base is maintained by Tweag.
To contribute please see the Design Document for instructions and advice on making pull requests.
Licence
See the Licence file.
Copyright © Tweag Holding and its affiliates.