@hackage liblawless0.23.0

Prelude based on protolude for GHC 8 and beyond.

liblawless: An Effectful Foundation

Overview

liblawless is a replacement for the standard Prelude. It targets GHC 8.0 and newer. It's core is building a fine-grained but readily accessible Effect model to move more type checking of code that changes its environment out of plain IO.

Pure vs Effectful Functions

Pure functions don't affect the anything outside of the function. A Pure function will run a calculation on the given values, and return a result. If you pass in the same parameters, you'll always get the same result no matter how many times you call the function.

Effectful functions are functions that do affect the program outside the function, and often the environment outside the computer running them. Even with the same parameters, Effectful Functions can return different results. In many cases they can even return signals that completing their task wasn't possible. In many languages these are called "Side Effects", and aren't modeled in the type system at all. Haskell comes with a simple Effect model in its type system, the [io][IO monad].

Kinds of Effects

The [io][IO monad] models Effects a function has on the world outside the program. There are other, more limited Effects as well, and there are libraries for managing these as well. The two most common are:

  • [transformers][Transformers]
  • [mtl][The MTL]

[transformers]: http://hackage.haskell.org/package/transformers Transformers [mtl]: http://hackage.haskell.org/package/mtl

These model Effects that only apply to the current program, while the IO monad models ''all other effects'' on the world. That's a really broad brush. Most bugs in Haskell code are in the IO monad.

This project is implementing several extra types of Effects that affect the world. Instead of treating them all the same, though, it breaks them up into much smaller kinds of Effects. For example, for accessing files, it's possible to:

  • read bytes from a file
  • write bytes to a file
  • read lines of text from a file
  • write lines of text from a file
  • read arbitrary data from a file, operate on these data items, and write them to a network stream
  • many other simple and complex operations

We are building them on top of the machines library. This library offers a composable model for connecting strongly-typed streams together. It also implements provisions for arbitrary effects, and connecting Effectful functions with Pure functions into streams of computations. When combined with the async library, these streams, and even individual nodes in these streams, can be run concurrently and safely, making full use of multicore systems.