HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Moduletransformers-0.6.1.1Haskell2010

Control.Monad.Trans.Reader

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.

  • 2 types
  • 11 values

The Reader monad

5 declarations
valuereader :: Monad m => (r -> a) -> ReaderT r m a
#

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

valuerunReader
  1. :: Reader r a

    A Reader to run.

  2. -> r

    An initial environment.

  3. -> a
#

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

The ReaderT monad transformer

3 declarations
newtypenewtype ReaderT r (m :: Type -> Type) a
#

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:

image: images/bind-ReaderT.svg

Constructors

Instances15Generic1, MonadTrans, Monad, Functor, MonadFix, MonadFail, …

Reader operations

3 declarations
valueasks
  1. :: Monad m
  2. => (r -> a)

    The selector function to apply to the environment.

  3. -> ReaderT r m a
#

Retrieve a function of the current environment.

Lifting other operations

2 declarations