Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reader and MonadReader

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!

like image 245
andro Avatar asked Sep 07 '16 09:09

andro


1 Answers

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)).
like image 73
leftaroundabout Avatar answered Sep 28 '22 03:09

leftaroundabout