HORIZON HASKELLDocslts/ghc-10.0.x04404a62026-10-19Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 04404a6 · 2026-10-19

Modulemtl-2.3.2Haskell2010

Control.Monad.RWS.Strict

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

Contents
  1. The RWS monad
  2. The RWST monad transformer
  3. Strict Reader-writer-state monads
Synopsis
  • Packagemtl-2.3.2
  • Exports13
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceStrict.hs

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

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.

Strict Reader-writer-state monads