Portability | portable |
---|---|
Stability | experimental |
Maintainer | libraries@haskell.org |
Declaration of the MonadReader class
Inspired by the paper /Functional Programming with Overloading and Higher-Order Polymorphism/, Mark P Jones (http://www.cse.ogi.edu/~mpj/) Advanced School of Functional Programming, 1995.
- type Reader r = ReaderT r Identity
- 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 w m a -> ReaderT w 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.
The return
function creates a Reader
that ignores the environment,
and produces the given value.
The binding operator >>=
produces a Reader
that uses the
environment to extract the value its left-hand side, and then applies
the bound function to that value in the same environment.
:: Reader r a | A |
-> r | An initial environment. |
-> a |
Runs Reader
and extracts the final value from it.
withReader :: (r' -> r) -> Reader r a -> Reader r' aSource
A more general version of local
.
The ReaderT monad transformer
The reader monad transformer. Can be used to add environment reading functionality to other monads.
ReaderT | |
|
mapReaderT :: (m a -> n b) -> ReaderT w m a -> ReaderT w n bSource
withReaderT :: (r' -> r) -> ReaderT r m a -> ReaderT r' m aSource
Reader operations
Lifting other operations
liftCallCC :: (((a -> m b) -> m a) -> m a) -> ((a -> ReaderT r m b) -> ReaderT r m a) -> ReaderT r m aSource
Lift a callCC
operation to the new monad.