This module defines the reader monad transformer, ReaderT.


newtype ReaderT r m a

The reader monad transformer.

This monad transformer extends the base monad transformer with a global context of type r.

The MonadReader type class describes the operations supported by this monad.




runReaderT :: forall r m a. ReaderT r m a -> (r -> m a)

Run a computation in the ReaderT monad.


mapReaderT :: forall r m1 m2 a b. (m1 a -> m2 b) -> ReaderT r m1 a -> ReaderT r m2 b

Change the type of the result in a ReaderT monad action.


withReaderT :: forall r1 r2 m a. (r2 -> r1) -> ReaderT r1 m a -> ReaderT r2 m a

Change the type of the context in a ReaderT monad action.

Re-exports from Control.Monad.Reader.Class


class (Monad m) <= MonadReader r m  where

The MonadReader type class represents those monads which support a global context via ask and local.

  • ask reads the current context.
  • local f x changes the value of the local context during the execution of the action x.

An implementation is provided for ReaderT, and for other monad transformers defined in this library.


  • do { ask ; ask } = ask
  • local f ask = f <$> ask
  • local _ (pure a) = pure a
  • local f (do { a <- x ; y }) = do { a <- local f x ; local f y }


  • local :: forall a. (r -> r) -> m a -> m a
  • ask :: m r



reader :: forall r m a. MonadReader r m => (r -> a) -> m a

Read a value which depends on the global context in any MonadReader.

Re-exports from Control.Monad.Trans


class MonadTrans t  where

The MonadTrans type class represents monad transformers.

A monad transformer is a type constructor of kind (* -> *) -> * -> *, which takes a Monad as its first argument, and returns another Monad.

This allows us to add additional effects to an existing monad. By iterating this process, we create monad transformer stacks, which contain all of the effects required for a particular computation.

The laws state that lift is a Monad morphism.


  • lift (pure a) = pure a
  • lift (do { x <- m ; y }) = do { x <- lift m ; lift y }