transformers-0.1.1.0: Concrete monad transformers

Portabilityportable
Stabilityexperimental
Maintainerlibraries@haskell.org

Control.Monad.Trans.Reader

Contents

Description

Declaration of the MonadReader class

Inspired by the paper /Functional Programming with Overloading and Higher-Order Polymorphism/, Mark P Jones (http://web.cecs.pdx.edu/~mpj/) Advanced School of Functional Programming, 1995.

Synopsis

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

runReaderSource

Arguments

:: 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.

Constructors

ReaderT 

Fields

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.