[Haskell-cafe] Monad transformers

Andrew Coppin andrewcoppin at btinternet.com
Sat Jul 3 10:07:17 EDT 2010

Roman Cheplyaka wrote:
> * Andrew Coppin <andrewcoppin at btinternet.com> [2010-07-03 14:20:14+0100]
>> In my experience, using more than one monad transformer at once makes
>> code utterly incomprehensible.
> See X monad (xmonad) for an counterexample.
> -- | The X monad, 'ReaderT' and 'StateT' transformers over 'IO'
> -- encapsulating the window manager configuration and state,
> -- respectively.
> --
> -- Dynamic components may be retrieved with 'get', static components
> -- with 'ask'. With newtype deriving we get readers and state monads
> -- instantiated on 'XConf' and 'XState' automatically.
> --
> newtype X a = X (ReaderT XConf (StateT XState IO) a)

In my experience, defining a type representing several stacked monad 
transformers is the easy part. The hard part is figuring out how in the 
name of God to run the resulting computation, or how to access functions 
burried at various levels of the stack.

 From what I've seen, it usually ends up being faster and easier to just 
define a custom monad that does exactly what you want, and then use that.

More information about the Haskell-Cafe mailing list