The Reader monad
type Reader r = ReaderT r Identity
The parameterizable reader monad, which is non-strict.
Computations are functions of a shared environment.
The return function ignores the environment, while m >>= k
passes the inherited environment to both subcomputations:
<<images/bind-ReaderT.svg>>
reader :: (Monad m) => (r -> a) -> ReaderT r m a
Constructor for computations in the reader monad (equivalent to asks).
runReader :: Reader r a -> r -> a
Runs a Reader and extracts the final value from it.
(The inverse of reader.)
A Reader to run.
mapReader :: (a -> b) -> Reader r a -> Reader r b
Transform the value returned by a Reader.
withReader :: (r' -> r) -> Reader r a -> Reader r' a
Execute a computation in a modified environment
(a specialization of withReaderT).
Computation to run in the modified environment.
(r' -> r)The function to modify the environment.
The reader monad transformer,
which adds a read-only environment to the given monad.
The return function ignores the environment, while m >>= k
passes the inherited environment to both subcomputations:
<<images/bind-ReaderT.svg>>
ReaderT r m is strict if and only if m is.
ReaderT :: r -> m a -> ReaderT r m a
runReaderT :: ReaderT r m a -> r -> m a
mapReaderT :: (m a -> n b) -> ReaderT r m a -> ReaderT r n b
Transform the computation inside a ReaderT.
withReaderT :: (r' -> r) -> ReaderT r m a -> ReaderT r' m a
Execute a computation in a modified environment
(a more general version of local).
Computation to run in the modified environment.
(r' -> r)The function to modify the environment.
Reader operations
ask :: (Monad m) => ReaderT r m r
Fetch the value of the environment.
local :: (r -> r) -> ReaderT r m a -> ReaderT r m a
Execute a computation in a modified environment
(a specialization of withReaderT).
Computation to run in the modified environment.
(r -> r)The function to modify the environment.
asks :: (Monad m) => (r -> a) -> ReaderT r m a
Retrieve a function of the current environment.
(r -> a)The selector function to apply to the environment.
Lifting other operations
liftCallCC :: CallCC m a b -> CallCC (ReaderT r m) a b
Lift a callCC operation to the new monad.
liftCatch :: Catch e m a -> Catch e (ReaderT r m) a
Lift a catchE operation to the new monad.
Instances
13
instance (Generic r, Generic m, Generic a) => Generic (ReaderT r m a)instance (Generic1 r, Generic1 m, Generic1 a) => Generic1 (ReaderT r m a)instance (Functor m) => Functor (ReaderT r m)instance (Applicative m) => Applicative (ReaderT r m)instance (Alternative m) => Alternative (ReaderT r m)instance (Monad m) => Monad (ReaderT r m)instance (Fail.MonadFail m) => Fail.MonadFail (ReaderT r m)instance (MonadPlus m) => MonadPlus (ReaderT r m)instance (MonadFix m) => MonadFix (ReaderT r m)instance MonadTrans (ReaderT r)instance (MonadIO m) => MonadIO (ReaderT r m)instance (MonadZip m) => MonadZip (ReaderT r m)instance Contravariant m => Contravariant (ReaderT r m)
- Maintainer
- R.Paterson@city.ac.uk
- Portability
- portable
- Copyright
- (c) Andy Gill 2001, (c) Oregon Graduate Institute of Science and Technology, 2001
- License
- BSD-style (see the file LICENSE)