HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulerebase-1.21.2Haskell2010

Rebase.Control.Monad.Trans.State

  • 2 types
  • 21 values
  • Packagerebase-1.21.2
  • Exports23
  • LanguageHaskell2010
  • LicenceMIT
  • SourceLazy.hs
typetype State s = StateT s Identity
#

A state monad parameterized by the type s of the state to carry.

The return function leaves the state unchanged, while >>= uses the final state of the first computation as the initial state of the second.

newtypenewtype StateT s (m :: Type -> Type) a
#

A state transformer monad parameterized by:

  • s - The state.

  • m - The inner monad.

The return function leaves the state unchanged, while >>= uses the final state of the first computation as the initial state of the second.

Constructors

Instances39MonadAccum, MonadError, MonadReader, MonadState, MonadWriter, MonadSelect, …
valueevalState
  1. :: State s a

    state-passing computation to execute

  2. -> s

    initial value

  3. -> a

    return value of the state computation

#

Evaluate a state computation with the given initial state and return the final value, discarding the final state.

valueexecState
  1. :: State s a

    state-passing computation to execute

  2. -> s

    initial value

  3. -> s

    final state

#

Evaluate a state computation with the given initial state and return the final state, discarding the final value.

valuerunState
  1. :: State s a

    state-passing computation to execute

  2. -> s

    initial state

  3. -> (a, s)

    return value and final state

#

Unwrap a state monad computation as a function. (The inverse of state.)

valueliftCallCC :: CallCC m (a, s) (b, s) -> CallCC (StateT 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.

valueget :: Monad m => StateT s m s
#

Fetch the current value of the state within the monad.

valuegets :: Monad m => (s -> a) -> StateT s m a
#

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

valueput :: Monad m => s -> StateT s m ()
#

put s sets the state within the monad to s.

valuestate
  1. :: Monad m
  2. => (s -> (a, s))

    pure state transformer

  3. -> StateT s m a

    equivalent state-passing computation

#

Construct a state monad computation from a function. (The inverse of runState.)

valueliftCallCC' :: CallCC m (a, s) (b, s) -> CallCC (StateT 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. It does not satisfy the uniformity property (see Control.Monad.Signatures).

valuemodifyM :: Monad m => (s -> m s) -> StateT s m ()
#

A variant of modify in which the new state is generated by a monadic action.