Module

Control.Monad.Reader.Trans

Package
purescript-transformers
Repository
purescript/purescript-transformers

This module defines the reader monad transformer, ReaderT.

#ReaderT Source

newtype ReaderT r m a

Constructors

Instances

#runReaderT Source

runReaderT :: forall r m a. ReaderT r m a -> (r -> m a)

Run a computation in the ReaderT monad.

#withReaderT Source

withReaderT :: forall r1 r2 m a. (r2 -> r1) -> ReaderT r1 m a -> ReaderT r2 m a

Change the type of the context in a ReaderT monad action.

#mapReaderT Source

mapReaderT :: forall r m1 m2 a b. (m1 a -> m2 b) -> ReaderT r m1 a -> ReaderT r m2 b

Change the type of the result in a ReaderT monad action.

Re-exports from Control.Monad.Reader.Class

#MonadAsk Source

class (Monad m) <= MonadAsk r m | m -> r where

The MonadAsk type class represents those monads which support a global context that can be provided via the ask function.

An implementation is provided for ReaderT, and for other monad transformers defined in this library.

Law:

  • do { ask ; ask } = ask

Members

Instances

#MonadReader Source

class (MonadAsk r m) <= MonadReader r m | m -> r where

An extension of the MonadAsk class that introduces a function local f x that allows the value of the local context to be modified for the duration of the execution of action x.

An implementation is provided for ReaderT, and for other monad transformers defined in this library.

Laws in addition to the MonadAsk law:

  • local f ask = f <$> ask
  • local _ (pure a) = pure a
  • local f (do { a <- x ; y }) = do { a <- local f x ; local f y }

Members

  • local :: forall a. (r -> r) -> m a -> m a

Instances

#asks Source

asks :: forall r m a. MonadAsk r m => (r -> a) -> m a

Projects a value from the global context in a MonadAsk.

Re-exports from Control.Monad.Trans.Class

#MonadTrans Source

class MonadTrans t  where

The MonadTrans type class represents monad transformers.

A monad transformer is a type constructor of kind (* -> *) -> * -> *, which takes a Monad as its first argument, and returns another Monad.

This allows us to add additional effects to an existing monad. By iterating this process, we create monad transformer stacks, which contain all of the effects required for a particular computation.

The laws state that lift is a Monad morphism.

Laws:

  • lift (pure a) = pure a
  • lift (do { x <- m ; y }) = do { x <- lift m ; lift y }

Members