Haskell source for the paper Monad Transformers Step by Step by Martin Grabmüller, tweaked to work in 2020 and built using Stack.
- Shared data structureds can be found in Lib.hs
- Each of the
eval0..eval6implementations can be found in ./src under a similarly named file. - Examples of each
eval*function running can be found in the test file.
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).
-
In Lib.hs,
Eqwas added to thederivingblock ofExpandValue. -
As
failwas removed from Monad, I've replaced calls tofailwitherror. -
I added a
MonadFailinstance forIdentityin Lib.hs- more info can be found here https://wiki.haskell.org/MonadFail_Proposal, see the
Adapting old codesection
- more info can be found here https://wiki.haskell.org/MonadFail_Proposal, see the
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.Exceptis used in place ofimport Control.Monad.Error, asControl.Monad.Errorhas been deprecated.- as the result of this, you'll see
ErrorTreplaced byExceptTin most of the examples.
- as the result of this, you'll see
git clone https://github.com/metadave/monad-transformers-step-by-step.git
cd monad-transformers-step-by-step
stack test
# - or-
stack ghcistack ghci
import qualified Data.Map as Map
eval0 Map.empty exampleExp
-- will display:
IntVal 18
- Figure out how to test the eval2* functions
The following repos contain similar implementations, although they don't seem to work in 2020: