layers-0.1: Modular type class machinery for monad transformer stacks.

Safe HaskellNone



This module exports:

  1. The MonadReader type class and its operations reader, ask and local.
  2. An instance of MonadReader for the -> type.
  3. Instances of MonadReader for the relevant monad transformers from the transformers package (ReaderT', lazy RWST and strict RWST).
  4. A universal pass-through instance of MonadReader for any existing MonadReader wrapped by a MonadLayer.
  5. The utility operations asks.



class Monad m => MonadReader r m | m -> r whereSource

The 'MonadReader interface monad represents computations which can read values from a shared environment, pass values from function to function and execute sub-computations in a modified environment. Using the MonadReader interface for such computations is often clearer and easier than using the MonadState interface.

Minimal complete definition: local and one of either reader or ask.


reader :: (r -> a) -> m aSource

Embed a simple reader action into the monad.

ask :: m rSource

Retrieves the monad environment.

local :: (r -> r) -> m a -> m aSource

Executes a computation in a modified environment.


(MonadLayer m, MonadReader r (Inner m)) => MonadReader r m 
MonadReader r ((->) r) 
(MonadReader r f, MonadReader r g) => MonadReader r (Product f g) 
Monad m => MonadReader r (ReaderT r m) 
(Monad m, Monoid w) => MonadReader r (RWST r w s m) 
(Monad m, Monoid w) => MonadReader r (RWST r w s m) 

asks :: MonadReader r m => (r -> a) -> m aSource

Retrieves a function of the current environment.