Reader and MonadReader

Why is there a Reader monad and a MonadReader monad in Control.Monad.Reader? The package documentation talks about the monad Reader, and then runs directly into the MonadReader documentation without explanation. What is the difference between these monads? Reading these man pages leaves me more than confused. Interestingly, the monad reader page for the Haskell wikibook has not yet been written!

+5
source share
1 answer

No monad MonadReader . This is a class of monads, namely those monads that can be used as Reader (usually because they are defined as stacks of a monad transformer with ReaderT somewhere). In this way,

  • Reader is a specific monad that acts only as a reader, because ReaderT applies only to a trivial monodal monode:

     type Reader r = ReaderT r Identity 

    So this is obviously an instance of MonadReader , but does nothing.

  • MonadReader is a class of all monads that can be read from some environment. Again, this includes Reader itself, but also MaybeT (ReaderT Int (ListT IO)) .
+12
source

All Articles