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!
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 has ReaderT
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 includes Reader
itself, but also MaybeT (ReaderT Int (ListT IO))
.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With