transformers-0.5.5.0: Concrete functor and monad transformers

Copyright (c) Andy Gill 2001(c) Oregon Graduate Institute of Science and Technology 2001 BSD-style (see the file LICENSE) R.Paterson@city.ac.uk experimental portable Safe Haskell98

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

Computations are functions of a shared environment.

The return function ignores the environment, while >>= passes the inherited environment to both subcomputations.

Constructor for computations in the reader monad (equivalent to asks).

Arguments

 :: Reader r a A Reader to run. -> r An initial environment. -> a

Runs a Reader and extracts the final value from it. (The inverse of reader.)

Transform the value returned by a Reader.

• runReader (mapReader f m) = f . runReader m

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 (withReader f m) = runReader m . f

newtype ReaderT r m a Source #

The return function ignores the environment, while >>= passes the inherited environment to both subcomputations.

Constructors

Instances

mapReaderT :: (m a -> n b) -> ReaderT r m a -> ReaderT r n b Source #

Transform the computation inside a ReaderT.

• runReaderT (mapReaderT f m) = f . runReaderT m

Arguments

 :: (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 (withReaderT f m) = runReaderT m . f

Fetch the value of the environment.

Arguments

 :: (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 (local f m) = runReaderT m . f

Arguments

 :: Monad m => (r -> a) The selector function to apply to the environment. -> ReaderT r m a

Retrieve a function of the current environment.

• asks f = liftM f ask

# Lifting other operations

liftCallCC :: CallCC m a b -> CallCC (ReaderT r m) a b Source #

Lift a callCC operation to the new monad.

liftCatch :: Catch e m a -> Catch e (ReaderT r m) a Source #

Lift a catchE operation to the new monad.