HORIZON HASKELLDocslts/ghc-10.0.x77a86622026-10-31Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 77a8662 · 2026-10-31

Moduletransformers-0.6.3.0Haskell2010

Control.Monad.Trans.RWS.Strict

A monad transformer that combines ReaderT, WriterT and StateT. This version is strict; for a lazy version with the same interface, see Control.Monad.Trans.RWS.Lazy. Although the output is built strictly, it is not possible to achieve constant space behaviour with this transformer: for that, use Control.Monad.Trans.RWS.CPS instead.

Contents
  1. The RWS monad
  2. The RWST monad transformer
  3. Reader operations
  4. Writer operations
  5. State operations
  6. Lifting other operations
Synopsis

The RWS monad

typetype RWS r w s = RWST r w s Identity

A monad containing an environment of type r, output of type w and an updatable state of type s.

valuerws :: (r -> s -> (a, s, w)) -> RWS r w s a

Construct an RWS computation from a function. (The inverse of runRWS.)

valuerunRWS :: RWS r w s a -> r -> s -> (a, s, w)

Unwrap an RWS computation as a function. (The inverse of rws.)

valueevalRWS
  1. :: RWS r w s a

    RWS computation to execute

  2. -> r

    initial environment

  3. -> s

    initial value

  4. -> (a, w)

    final value and output

Evaluate a computation with the given initial state and environment, returning the final value and output, discarding the final state.

valueexecRWS
  1. :: RWS r w s a

    RWS computation to execute

  2. -> r

    initial environment

  3. -> s

    initial value

  4. -> (s, w)

    final state and output

Evaluate a computation with the given initial state and environment, returning the final state and output, discarding the final value.

valuemapRWS :: ((a, s, w) -> (b, s, w')) -> RWS r w s a -> RWS r w' s b

Map the return value, final state and output of a computation using the given function.

The RWST monad transformer

newtypenewtype RWST r w s (m :: Type -> Type) a

A monad transformer adding reading an environment of type r, collecting an output of type w and updating a state of type s to an inner monad m.

Constructors

Instances12MonadTrans, Monad, Functor, MonadFix, MonadFail, Applicative, …
valueevalRWST
  1. :: Monad m
  2. => RWST r w s m a

    computation to execute

  3. -> r

    initial environment

  4. -> s

    initial value

  5. -> m (a, w)

    computation yielding final value and output

Evaluate a computation with the given initial state and environment, returning the final value and output, discarding the final state.

valueexecRWST
  1. :: Monad m
  2. => RWST r w s m a

    computation to execute

  3. -> r

    initial environment

  4. -> s

    initial value

  5. -> m (s, w)

    computation yielding final state and output

Evaluate a computation with the given initial state and environment, returning the final state and output, discarding the final value.

Reader operations

Writer operations

valuewriter :: Monad m => (a, w) -> RWST r w s m a

Construct a writer computation from a (result, output) pair.

valuepass :: Monad m => RWST r w s m (a, w -> w) -> RWST r w s m a

pass m is an action that executes the action m, which returns a value and a function, and returns the value, applying the function to the output.

State operations

valuestate :: (Monoid w, Monad m) => (s -> (a, s)) -> RWST r w s m a

Construct a state monad computation from a state transformer function.

Lifting other operations

valueliftCallCC
  1. :: Monoid w
  2. => CallCC m (a, s, w) (b, s, w)
  3. -> CallCC (RWST r w s m) a b

Uniform lifting of a callCC operation to the new monad. This version rolls back to the original state on entering the continuation.

valueliftCallCC'
  1. :: Monoid w
  2. => CallCC m (a, s, w) (b, s, w)
  3. -> CallCC (RWST r w s m) a b

In-situ lifting of a callCC operation to the new monad. This version uses the current state on entering the continuation.

valueliftCatch :: Catch e m (a, s, w) -> Catch e (RWST r w s m) a

Lift a catchE operation to the new monad. The uniformity property (see Control.Monad.Signatures) implies that the lifted catchE discards any output or changes to the state from the body on entering the handler.