Portability | portable |
---|---|
Stability | experimental |
Maintainer | libraries@haskell.org |
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.
- 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 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 r a | A |
-> r | An initial environment. |
-> a |
Runs a Reader
and extracts the final value from it.
:: (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
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.
ReaderT | |
|
MonadTrans (ReaderT r) | |
Monad m => Monad (ReaderT r m) | |
Functor m => Functor (ReaderT r m) | |
MonadFix m => MonadFix (ReaderT r m) | |
MonadPlus m => MonadPlus (ReaderT r m) | |
Applicative m => Applicative (ReaderT r m) | |
Alternative m => Alternative (ReaderT r m) | |
MonadIO m => MonadIO (ReaderT r m) |
mapReaderT :: (m a -> n b) -> ReaderT r m a -> ReaderT r n bSource
Transform the computation inside a ReaderT
.
:: (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
:: 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
).
Retrieve a function of the current environment.