Skip to content

bookshelfdave/monad-transformers-step-by-step

Repository files navigation

Monad Transformers Step by Step

Haskell source for the paper Monad Transformers Step by Step by Martin Grabmüller, tweaked to work in 2020 and built using Stack.

How this repo is organized

  • Shared data structureds can be found in Lib.hs
  • Each of the eval0 .. eval6 implementations can be found in ./src under a similarly named file.
  • Examples of each eval* function running can be found in the test file.

Changes

I've made the following changes to the example source in order for it to compile with the "latest" Haskell tools (as of May 2020).

Without the MonadFail instance above, you'll get compilation errors like this:

   • No instance for (MonadFail Identity)
        arising from a do statement
        with the failable pattern ‘IntVal i2’
    • In a stmt of a 'do' block: IntVal i2 <- eval2c env e2
      In the expression:
        do IntVal i1 <- eval2c env e1
           IntVal i2 <- eval2c env e2
           return $ IntVal (i1 + i2)
      In an equation for ‘eval2c’:
          eval2c env (Plus e1 e2)
            = do IntVal i1 <- eval2c env e1
                 IntVal i2 <- eval2c env e2
                 return $ IntVal (i1 + i2)
   |
52 |                                  IntVal i2  <- eval2c env e2
   |                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  • Control.Monad.Except is used in place of import Control.Monad.Error, as Control.Monad.Error has been deprecated.
    • as the result of this, you'll see ErrorT replaced by ExceptT in most of the examples.

Building

git clone https://github.com/metadave/monad-transformers-step-by-step.git
cd monad-transformers-step-by-step
stack test
 # - or-
stack ghci

Interactive Examples

stack ghci

import qualified Data.Map as Map
eval0 Map.empty exampleExp
-- will display:
IntVal 18

TODO

  • Figure out how to test the eval2* functions

Similar repos

The following repos contain similar implementations, although they don't seem to work in 2020:

About

(unofficial) source for Monad Transformers Step by Step by Martin Grabmüller

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published