transformers-0.4.0.0: Concrete functor and monad transformers

Portabilityportable
Stabilityexperimental
Maintainerross@soi.city.ac.uk
Safe HaskellSafe-Inferred

Control.Monad.Trans.Reader

Contents

Description

Declaration of the ReaderT monad transformer, which adds a static environment to a given monad.

If the computation is to modify the stored information, use Control.Monad.Trans.State instead.

Synopsis

The Reader monad

type Reader r = ReaderT r IdentitySource

The parameterizable reader monad.

Computations are functions of a shared environment.

The return function ignores the environment, while >>= passes the inherited environment to both subcomputations.

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

Constructor for computations in the reader monad (equivalent to asks).

runReaderSource

Arguments

:: Reader r a

A Reader to run.

-> r

An initial environment.

-> a 

Runs a Reader and extracts the final value from it. (The inverse of reader.)

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

Transform the value returned by a Reader.

withReaderSource

Arguments

:: (r' -> r)

The function to modify the environment.

-> Reader r a

Computation to run in the modified environment.

-> Reader r' a 

Execute a computation in a modified environment (a specialization of withReaderT).

The ReaderT monad transformer

newtype ReaderT r m a Source

The reader monad transformer, which adds a read-only environment to the given monad.

The return function ignores the environment, while >>= passes the inherited environment to both subcomputations.

Constructors

ReaderT (r -> m a) 

runReaderT :: ReaderT r m a -> r -> m aSource

The underlying computation, as a function of the environment. (inverse of ReaderT)

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

Transform the computation inside a ReaderT.

withReaderTSource

Arguments

:: (r' -> r)

The function to modify the environment.

-> ReaderT r m a

Computation to run in the modified environment.

-> ReaderT r' m a 

Execute a computation in a modified environment (a more general version of local).

Reader operations

ask :: Monad m => ReaderT r m rSource

Fetch the value of the environment.

localSource

Arguments

:: Monad m 
=> (r -> r)

The function to modify the environment.

-> ReaderT r m a

Computation to run in the modified environment.

-> ReaderT r m a 

Execute a computation in a modified environment (a specialization of withReaderT).

asksSource

Arguments

:: Monad m 
=> (r -> a)

The selector function to apply to the environment.

-> ReaderT r m a 

Retrieve a function of the current environment.

Lifting other operations

liftCallCC :: CallCC m a b -> CallCC (ReaderT r m) a bSource

Lift a callCC operation to the new monad.

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

Lift a catchE operation to the new monad.