9
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:
base type ('Base')
- Monad instance
transformer type ('BaseT')
Monad instance
MonadTrans instance
MonadIO instance
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:
- what the relationships and differences are between the "BaseT"s and the corresponding "MonadBase"s and "Base"s
- whether all three are required
- how MonadTrans is related and what its purpose is