transformers-0.2.1.0: Concrete functor and monad transformersContentsIndex
Control.Monad.Trans.Reader
Portabilityportable
Stabilityexperimental
Maintainerlibraries@haskell.org
Contents
The Reader monad
The ReaderT monad transformer
Reader operations
Lifting other operations
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
type Reader r = ReaderT r Identity
reader :: (r -> a) -> Reader r a
runReader :: Reader r a -> r -> a
mapReader :: (a -> b) -> Reader r a -> Reader r b
withReader :: (r' -> r) -> Reader r a -> Reader r' a
newtype ReaderT r m a = ReaderT {
runReaderT :: r -> m a
}
mapReaderT :: (m a -> n b) -> ReaderT r m a -> ReaderT r n b
withReaderT :: (r' -> r) -> ReaderT r m a -> ReaderT r' m a
ask :: Monad m => ReaderT r m r
local :: Monad m => (r -> r) -> ReaderT r m a -> ReaderT r m a
asks :: Monad m => (r -> a) -> ReaderT r m a
liftCallCC :: (((a -> m b) -> m a) -> m a) -> ((a -> ReaderT r m b) -> ReaderT r m a) -> ReaderT r m a
liftCatch :: (m a -> (e -> m a) -> m a) -> ReaderT r m a -> (e -> ReaderT r m a) -> ReaderT r m a
The Reader monad
type Reader r = ReaderT r Identity

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 :: (r -> a) -> Reader r a
Constructor for computations in the reader monad.
runReader
:: Reader r aA Reader to run.
-> rAn initial environment.
-> a
Runs a Reader and extracts the final value from it.
mapReader :: (a -> b) -> Reader r a -> Reader r b
Transform the value returned by a Reader.
withReader
:: (r' -> r)The function to modify the environment.
-> Reader r aComputation 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

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
runReaderT :: r -> m aThe underlying computation, as a function of the environment.
show/hide Instances
mapReaderT :: (m a -> n b) -> ReaderT r m a -> ReaderT r n b
Transform the computation inside a ReaderT.
withReaderT
:: (r' -> r)The function to modify the environment.
-> ReaderT r m aComputation 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 r
Fetch the value of the environment.
local
:: Monad m
=> (r -> r)The function to modify the environment.
-> ReaderT r m aComputation to run in the modified environment.
-> ReaderT r m a
Execute a computation in a modified environment (a specialization of withReaderT).
asks
:: 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
:: (((a -> m b) -> m a) -> m a)callCC on the argument monad.
-> ((a -> ReaderT r m b) -> ReaderT r m a)
-> ReaderT r m a
Lift a callCC operation to the new monad.
liftCatch
:: (m a -> (e -> m a) -> m a)catch on the argument monad.
-> ReaderT r m aComputation to attempt.
-> (e -> ReaderT r m a)Exception handler.
-> ReaderT r m a
Lift a catchError operation to the new monad.
Produced by Haddock version 2.7.2