transformers- Concrete monad transformers





Declaration of the MonadReader class

Inspired by the paper /Functional Programming with Overloading and Higher-Order Polymorphism/, Mark P Jones ( Advanced School of Functional Programming, 1995.


The Reader monad

type Reader r = ReaderT r IdentitySource

The parameterizable reader monad.

The return function creates a Reader that ignores the environment, and produces the given value.

The binding operator >>= produces a Reader that uses the environment to extract the value its left-hand side, and then applies the bound function to that value in the same environment.

reader :: (r -> a) -> Reader r aSource



:: Reader r a

A Reader to run.

-> r

An initial environment.

-> a 

Runs Reader and extracts the final value from it.

mapReader :: (a -> b) -> Reader r a -> Reader r bSource

withReader :: (r' -> r) -> Reader r a -> Reader r' aSource

A more general version of local.

The ReaderT monad transformer

newtype ReaderT r m a Source

The reader monad transformer. Can be used to add environment reading functionality to other monads.




runReaderT :: r -> m a

mapReaderT :: (m a -> n b) -> ReaderT w m a -> ReaderT w n bSource

withReaderT :: (r' -> r) -> ReaderT r m a -> ReaderT r' m aSource

Reader operations

ask :: Monad m => ReaderT r m rSource

local :: Monad m => (r -> r) -> ReaderT r m a -> ReaderT r m aSource

asks :: Monad m => (r -> a) -> ReaderT r m aSource

Lifting other operations

liftCallCC :: (((a -> m b) -> m a) -> m a) -> ((a -> ReaderT r m b) -> ReaderT r m a) -> ReaderT r m aSource

Lift a callCC operation to the new monad.

liftCatch :: (m a -> (e -> m a) -> m a) -> ReaderT r m a -> (e -> ReaderT r m a) -> ReaderT r m aSource

Lift a catchError operation to the new monad.