I'm trying to learn monad transformers, based on the standard Haskell libraries (mtl? transformers? not sure which one came with my download of the Haskell platform - 7.4.1).

What I believe I've noticed is a common structure for each monad transformer definition:

  1. base type ('Base')

    • Monad instance
  2. transformer type ('BaseT')

    • Monad instance

    • MonadTrans instance

    • MonadIO instance

  3. transformer class ('MonadBase')

    • some operations

    • instances for other 'BaseT's

So for example, for the Writer monad, there'd be:

  • a Writer datatype/newtype/type, with a Monad instance
  • a WriterT datatype/newtype/type, with Monad, MonadTrans, and MonadIO instances
  • a MonadWriter class, and instances of this class for StateT, ReaderT, IdentityT, ...

Is this how monad transformers are organized? Am I missing anything/do I have any incorrect details?

The motivation for this question is figuring out:

  1. what the relationships and differences are between the "BaseT"s and the corresponding "MonadBase"s and "Base"s
  2. whether all three are required
  3. how MonadTrans is related and what its purpose is
Edit
Report