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

Modulemtl-2.3.1Haskell2010

Control.Monad.RWS.CPS

Strict RWS monad that uses continuation-passing-style to achieve constant space usage.

Inspired by the paper Functional Programming with Overloading and Higher-Order Polymorphism, Mark P Jones (http://web.cecs.pdx.edu/~mpj/) Advanced School of Functional Programming, 1995.

Since: mtl-2.3, transformers-0.5.6

  • 2 types
  • 11 values
  • Packagemtl-2.3.1
  • Exports13
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceCPS.hs

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 :: Monoid w => (r -> s -> (a, s, w)) -> RWS r w s a
#

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

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

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

valueevalRWS
  1. :: Monoid w
  2. => RWS r w s a

    RWS computation to execute

  3. -> r

    initial environment

  4. -> s

    initial value

  5. -> (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. :: Monoid w
  2. => RWS r w s a

    RWS computation to execute

  3. -> r

    initial environment

  4. -> s

    initial value

  5. -> (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
  1. :: (Monoid w, Monoid w')
  2. => (a, s, w) -> (b, s, w')
  3. -> RWS r w s a
  4. -> RWS r w' s b
#

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

The RWST monad transformer

6 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.

Instances19MonadRWS, MonadAccum, MonadError, MonadReader, MonadState, MonadWriter, …
valuerunRWST :: Monoid w => RWST r w s m a -> r -> s -> m (a, s, w)
#

Unwrap an RWST computation as a function. (The inverse of rwsT.)

valueevalRWST
  1. :: (Monad m, Monoid w)
  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, Monoid w)
  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.

valuemapRWST
  1. :: (Monad n, Monoid w, Monoid w')
  2. => m (a, s, w) -> n (b, s, w')
  3. -> RWST r w s m a
  4. -> RWST r w' s n b
#

Map the inner computation using the given function.

  • runRWST (mapRWST f m) r s = f (runRWST m r s) mapRWST :: (m (a, s, w) -> n (b, s, w')) -> RWST r w s m a -> RWST r w' s n b

Strict Reader-writer-state monads

0 declarations