transformers-0.6.0.2: Concrete functor and monad transformers
Copyright(c) Andy Gill 2001
(c) Oregon Graduate Institute of Science and Technology 2001
LicenseBSD-style (see the file LICENSE)
MaintainerR.Paterson@city.ac.uk
Stabilityexperimental
Portabilityportable
Safe HaskellSafe
LanguageHaskell2010

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

The Reader monad

type Reader r = ReaderT r Identity Source #

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 :: Monad m => (r -> a) -> ReaderT r m a Source #

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

runReader Source #

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.)

mapReader :: (a -> b) -> Reader r a -> Reader r b Source #

Transform the value returned by a Reader.

withReader Source #

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).

The ReaderT monad transformer

newtype ReaderT r m a Source #

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.

Constructors

ReaderT 

Fields

Instances

Instances details
MonadTrans (ReaderT r) Source # 
Instance details

Defined in Control.Monad.Trans.Reader

Methods

lift :: Monad m => m a -> ReaderT r m a Source #

Generic1 (ReaderT r m :: Type -> Type) Source # 
Instance details

Defined in Control.Monad.Trans.Reader

Associated Types

type Rep1 (ReaderT r m) :: k -> Type #

Methods

from1 :: forall (a :: k). ReaderT r m a -> Rep1 (ReaderT r m) a #

to1 :: forall (a :: k). Rep1 (ReaderT r m) a -> ReaderT r m a #

Monad m => Monad (ReaderT r m) Source # 
Instance details

Defined in Control.Monad.Trans.Reader

Methods

(>>=) :: ReaderT r m a -> (a -> ReaderT r m b) -> ReaderT r m b #

(>>) :: ReaderT r m a -> ReaderT r m b -> ReaderT r m b #

return :: a -> ReaderT r m a #

Functor m => Functor (ReaderT r m) Source # 
Instance details

Defined in Control.Monad.Trans.Reader

Methods

fmap :: (a -> b) -> ReaderT r m a -> ReaderT r m b #

(<$) :: a -> ReaderT r m b -> ReaderT r m a #

MonadFix m => MonadFix (ReaderT r m) Source # 
Instance details

Defined in Control.Monad.Trans.Reader

Methods

mfix :: (a -> ReaderT r m a) -> ReaderT r m a #

MonadFail m => MonadFail (ReaderT r m) Source # 
Instance details

Defined in Control.Monad.Trans.Reader

Methods

fail :: String -> ReaderT r m a #

Applicative m => Applicative (ReaderT r m) Source # 
Instance details

Defined in Control.Monad.Trans.Reader

Methods

pure :: a -> ReaderT r m a #

(<*>) :: ReaderT r m (a -> b) -> ReaderT r m a -> ReaderT r m b #

liftA2 :: (a -> b -> c) -> ReaderT r m a -> ReaderT r m b -> ReaderT r m c #

(*>) :: ReaderT r m a -> ReaderT r m b -> ReaderT r m b #

(<*) :: ReaderT r m a -> ReaderT r m b -> ReaderT r m a #

Contravariant m => Contravariant (ReaderT r m) Source # 
Instance details

Defined in Control.Monad.Trans.Reader

Methods

contramap :: (a -> b) -> ReaderT r m b -> ReaderT r m a #

(>$) :: b -> ReaderT r m b -> ReaderT r m a #

MonadZip m => MonadZip (ReaderT r m) Source # 
Instance details

Defined in Control.Monad.Trans.Reader

Methods

mzip :: ReaderT r m a -> ReaderT r m b -> ReaderT r m (a, b) #

mzipWith :: (a -> b -> c) -> ReaderT r m a -> ReaderT r m b -> ReaderT r m c #

munzip :: ReaderT r m (a, b) -> (ReaderT r m a, ReaderT r m b) #

MonadIO m => MonadIO (ReaderT r m) Source # 
Instance details

Defined in Control.Monad.Trans.Reader

Methods

liftIO :: IO a -> ReaderT r m a #

Alternative m => Alternative (ReaderT r m) Source # 
Instance details

Defined in Control.Monad.Trans.Reader

Methods

empty :: ReaderT r m a #

(<|>) :: ReaderT r m a -> ReaderT r m a -> ReaderT r m a #

some :: ReaderT r m a -> ReaderT r m [a] #

many :: ReaderT r m a -> ReaderT r m [a] #

MonadPlus m => MonadPlus (ReaderT r m) Source # 
Instance details

Defined in Control.Monad.Trans.Reader

Methods

mzero :: ReaderT r m a #

mplus :: ReaderT r m a -> ReaderT r m a -> ReaderT r m a #

Generic (ReaderT r m a) Source # 
Instance details

Defined in Control.Monad.Trans.Reader

Associated Types

type Rep (ReaderT r m a) :: Type -> Type #

Methods

from :: ReaderT r m a -> Rep (ReaderT r m a) x #

to :: Rep (ReaderT r m a) x -> ReaderT r m a #

type Rep1 (ReaderT r m :: Type -> Type) Source # 
Instance details

Defined in Control.Monad.Trans.Reader

type Rep1 (ReaderT r m :: Type -> Type) = D1 ('MetaData "ReaderT" "Control.Monad.Trans.Reader" "transformers-0.6.0.2-3vZqekptSPoIT7uEdKk0Uz" 'True) (C1 ('MetaCons "ReaderT" 'PrefixI 'True) (S1 ('MetaSel ('Just "runReaderT") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (((->) r :: Type -> Type) :.: Rec1 m)))
type Rep (ReaderT r m a) Source # 
Instance details

Defined in Control.Monad.Trans.Reader

type Rep (ReaderT r m a) = D1 ('MetaData "ReaderT" "Control.Monad.Trans.Reader" "transformers-0.6.0.2-3vZqekptSPoIT7uEdKk0Uz" 'True) (C1 ('MetaCons "ReaderT" 'PrefixI 'True) (S1 ('MetaSel ('Just "runReaderT") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (r -> m a))))

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

Transform the computation inside a ReaderT.

withReaderT Source #

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).

Reader operations

ask :: Monad m => ReaderT r m r Source #

Fetch the value of the environment.

local Source #

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).

asks Source #

Arguments

:: Monad m 
=> (r -> a)

The selector function to apply to the environment.

-> ReaderT r m a 

Retrieve a function of the current environment.

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.