HORIZON HASKELLDocslts/ghc-10.0.x8174fa42026-10-11Search names, modules, packages, or :: a typeCtrl K

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8174fa4 · 2026-10-11

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.

  • 2 types
  • 28 values

The RWS monad

7 declarations
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

5 declarations
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

4 declarations
valuereader :: (Monoid w, Monad m) => (r -> a) -> RWST r w s m a
#

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

Writer operations

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

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

valuetell :: Monad m => w -> RWST r w s m ()
#

tell w is an action that produces the output w.

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

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

Construct a state monad computation from a state transformer function.

valueget :: (Monoid w, Monad m) => RWST r w s m s
#

Fetch the current value of the state within the monad.

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

Get a specific component of the state, using a projection function supplied.

Lifting other operations

3 declarations
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.