The project aims to get an overview of some of the most prominent (or emerging) effect systems:
- mtl/tagless final
- free monads
- ad hoc languages
The project starts from a rather dumb function that performs an effectful computation; in plain Scala:
def maybeDouble(n: Int): Int =
println("Flipping a coin!")
val heads = util.Random.nextBoolean
if head then n*2 else n
Then, for each effect system it shows:
- how to encode the function in the effect system
- how the core logic of the resulting code can be tested
- how the program could be interpreted in different ways
All the examples are written in Haskell, Scala and Unison: the projects have almost exactly the same structure so that if you know one of the languages it (hopefully) should not be too hard to follow the examples in the other.
Scala | Haskell | Unison (in ucm ) |
|
---|---|---|---|
run the interactive example | sbt run |
cabal run effects |
run coinFlip.main |
run the tests | sbt test |
cabal test |
test |
Unison is a content-addressed language and stores its code in a format that
GitHub can not currently show; that's why for now in the repository I included a simple code.u
file with
all thee definitions that would be stored in the codebase. It's just to make it easier to keep everything
in one place. However, I highly recommend to browse the Unison code directly from its
repository on Unison Share