Why is there a Reader monad and a MonadReader monad in Control.Monad.Reader? The package documentation talks about the Reader monad and then launches into the MonadReader documentation directly with no explanation. What is the difference between these monads? Reading these reference pages leaves me more than confused. Interestingly, the Reader monad page for the Haskell wikibook has yet to be written!
Asked
Active
Viewed 703 times
5
-
As I understand, this is an abstraction over anything which could behave like `Reader` monad. For example, it could be a stack of monad transformers. Please correct me if I'm wrong. – Sep 07 '16 at 09:32
1 Answers
17
There is no MonadReader
monad. That is a class of monads, namely of those monads that can be used as a Reader
(generally, because they're defined as a monad transformer stack with a ReaderT
in somewhere). So,
Reader
is the specific monad that only acts as a reader, because it hasReaderT
only applied to the trivial identity monad:type Reader r = ReaderT r Identity
It is thus obviously an instance of
MonadReader
, but doesn't do anything else.MonadReader
is is the class of all monads that can read from some environment. Again, this includesReader
itself, but alsoMaybeT (ReaderT Int (ListT IO))
.

leftaroundabout
- 117,950
- 5
- 174
- 319