September 2017
Beginner to intermediate
396 pages
9h 46m
English
The Reader monad is a monad transformer with the purpose of providing an environment. We use the monad transformer ReaderT :: r m a, which is defined in the Control.Monad.Reader module. In the mtl library, usually, each transformer has an associated type class. The transformer ReaderT is an instance of MonadReader type class:
class Monad m => MonadReader r (m :: * -> *) | m -> r where ask :: m r local :: (r -> r) -> m a -> m a reader :: (r -> a) -> m a
A special monad called Identity exists in Data.Functor.Identity, which is the simplest monad. Its only purpose is to embed a pure value into a monad. The Reader monad is defined as ReaderT with Identity as an embedded monad:
type Reader r = ReaderT r Identity
MonadReader
Read now
Unlock full access