Linear base is a standard library for developing applications with linear
types. It is named linear-base
to be an analog to the original base
package that ships with GHC.
The purpose of linear-base
is to provide the minimal facilities you need to
write practical Linear Haskell code, i.e., Haskell code that uses the
-XLinearTypes
language extension.
Why do you need linear-base
to write linear projects?
-
Data types, functions and classes in
base
are not linear types aware. For instance, ifn
is a linearly-boundInt
, 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 in-place mutation of arrays.
-XLinearTypes
is not yet part of any GHC release. We recommend using
Stack and Nix together to pull in an experimental version of GHC into
your project. Use this stack.yaml
as a starting
point for your project. To learn more about Stack+Nix integration, see
here.
All source files with linear types need a language extension pragma at the top:
{-# LANGUAGE LinearTypes #-}
If you already know what -XLinearTypes
does and what the linear
arrow a #-> b
means, then read the User Guide and explore the
examples/
folder to know how to use linear-base
.
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.
- See the
examples/
folder. - Linear examples on watertight 3D models
- 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
.
- Practical Linearity in a higher-order polymorphic language -- POPL 2018
- Practical Linearity in a higher-order polymorphic language -- Curry on 2018
- Practical Linearity in a higher-order polymorphic language -- Haskell Exchange 2018
- Implementing Linear Haskell
- In-place array update with linear types -- ZuriHac 2020
Linear base is maintained by Tweag.
To contribute please see the Design Document for instructions and advice on making pull requests.
See the Licence file.
Copyright ยฉ Tweag Holding and its affiliates.