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

Lazy RWS monad.

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.

  • 2 types
  • 11 values
  • Packagemtl-2.3.1
  • Exports13
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceLazy.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 :: (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

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.

Constructors

Instances20MonadRWS, MonadAccum, MonadError, MonadReader, MonadState, MonadWriter, …
valuerunRWST :: RWST r w s m a -> r -> s -> m (a, s, w)
#
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.

Lazy Reader-writer-state monads

0 declarations