Mon Apr 16 11:24:20 EDT 2012
Question: I know (intuitively) I want to combine 2 monads. How to
know which order they go in? For some the order doesn't matter, for
other it does.
Practically, I want to combine state and reader.
So I just used this:
runSR m = evalState (runReaderT m r0) s0
and the nice surprise is that operations are automatically lifted:
even if state is the inner monad, get/set/modify "just work".
See also "Monad Transformers Step by Step" .
To find out whether monads commute, it's probably best to just write
out the types (without wrappers) and verify manually. An example of a
pair of transformers that does not commute is MaybeT and StateT.