Edited at

Monad Transformer

More than 3 years have passed since last update.


Example Usage of Monad Transformer

The best tutorial of Monad Transformer is "Monad Transformers Step by Step" by Martin Grabmulle. The tutorial is available online. Code is available here


Construct your own Monad Transformer

To better understand Monad Transformer, you can implement your own Monad Transformers. For example:

https://github.com/seckcoder/Haskell-Demo/blob/master/src/MonadTransformer/MTL.hs


Problems of Monad Transformers:

http://blog.ezyang.com/2013/09/if-youre-using-lift-youre-doing-it-wrong-probably/

http://stackoverflow.com/questions/9054731/avoiding-lift-with-monad-transformers


One Monad Transformer shows up multiple times in the monad stack


-- Multiple Environments
type Eval a = ReaderT Env (ReaderT Env Identity) a

eval (Val n) = do env1 <- ask
env2 <- lift ask -- To get the inner environment, you need to lift the computation here
-- ...


Alternative to Monad Transformers

http://okmij.org/ftp/Haskell/extensible/