O'Reilly logo

Haskell Cookbook by Yogesh Sajanikar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works...

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required