| Copyright | (c) Andy Gill 2001 (c) Oregon Graduate Institute of Science and Technology 2001 | 
|---|---|
| License | BSD-style (see the file LICENSE) | 
| Maintainer | R.Paterson@city.ac.uk | 
| Stability | experimental | 
| Portability | portable | 
| Safe Haskell | Safe | 
| Language | Haskell2010 | 
Control.Monad.Trans.Reader
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 :: forall (m :: Type -> Type) r a. Monad m => (r -> a) -> ReaderT r m 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 :: Type -> Type) a = ReaderT {- runReaderT :: r -> m a
 
- mapReaderT :: (m a -> n b) -> ReaderT r m a -> ReaderT r n b
- withReaderT :: forall r' r (m :: Type -> Type) a. (r' -> r) -> ReaderT r m a -> ReaderT r' m a
- ask :: forall (m :: Type -> Type) r. Monad m => ReaderT r m r
- local :: forall r (m :: Type -> Type) a. (r -> r) -> ReaderT r m a -> ReaderT r m a
- asks :: forall (m :: Type -> Type) r a. Monad m => (r -> a) -> ReaderT r m a
- liftCallCC :: CallCC m a b -> CallCC (ReaderT r m) a b
- liftCatch :: Catch e m a -> Catch e (ReaderT r m) a
The Reader monad
reader :: forall (m :: Type -> Type) r a. Monad m => (r -> a) -> ReaderT r m a Source #
Constructor for computations in the reader monad (equivalent to asks).
Arguments
| :: Reader r a | A  | 
| -> r | An initial environment. | 
| -> a | 
Runs a Reader and extracts the final value from it.
 (The inverse of reader.)
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).
- runReader(- withReaderf m) =- runReaderm . f
The ReaderT monad transformer
newtype ReaderT r (m :: Type -> Type) a Source #
The reader monad transformer, which adds a read-only environment to the given monad.
The return function ignores the environment, while m 
 passes the inherited environment to both subcomputations:>>= k
Constructors
| ReaderT | |
| Fields 
 | |
Instances
mapReaderT :: (m a -> n b) -> ReaderT r m a -> ReaderT r n b Source #
Transform the computation inside a ReaderT.
- runReaderT(- mapReaderTf m) = f .- runReaderTm
Arguments
| :: forall r' r (m :: Type -> Type) a. (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).
- runReaderT(- withReaderTf m) =- runReaderTm . f
Reader operations
ask :: forall (m :: Type -> Type) r. Monad m => ReaderT r m r Source #
Fetch the value of the environment.
Arguments
| :: forall r (m :: Type -> Type) a. (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).
- runReaderT(- localf m) =- runReaderTm . f