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

Moduleadjunctions-4.4.3Haskell2010

Control.Monad.Representable.State

A generalized State monad, parameterized by a Representable functor. The representation of that functor serves as the state.

  • 2 types
  • 1 class
  • 11 values
  • Packageadjunctions-4.4.3
  • Exports14
  • LanguageHaskell2010
  • LicenceBSD-2-Clause
  • SourceState.hs
typetype State (g :: Type -> Type) = StateT g Identity
#

A memoized state monad parameterized by a representable functor g, where the representatation of g, Rep g is 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.

valuerunState
  1. :: Representable g
  2. => State g a

    state-passing computation to execute

  3. -> Rep g

    initial state

  4. -> (a, Rep g)

    return value and final state

#

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

valueevalState
  1. :: Representable g
  2. => State g a

    state-passing computation to execute

  3. -> Rep g

    initial value

  4. -> 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. :: Representable g
  2. => State g a

    state-passing computation to execute

  3. -> Rep g

    initial value

  4. -> Rep g

    final state

#

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

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

A state transformer monad parameterized by:

  • g - A representable functor used to memoize results for a state Rep g

  • 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

Instances12MonadReader, MonadState, MonadWriter, MonadFree, MonadTrans, BindTrans, …
valueliftCallCC
  1. :: Representable g
  2. => (((a, Rep g) -> m (b, Rep g)) -> m (a, Rep g)) -> m (a, Rep g)
  3. -> (a -> StateT g m b) -> StateT g m a
  4. -> StateT g m a
#

Uniform lifting of a callCC operation to the new monad. This version rolls back to the original state on entering the continuation.

valueliftCallCC'
  1. :: Representable g
  2. => (((a, Rep g) -> m (b, Rep g)) -> m (a, Rep g)) -> m (a, Rep g)
  3. -> (a -> StateT g m b) -> StateT g m a
  4. -> StateT g m a
#

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 laws of a monad transformer.

classclass Monad m => MonadState s (m :: Type -> Type) | m -> s where
#

Minimal definition is either both of get and put or just state

Methods

  • get :: m s

    Return the state from the internals of the monad.

  • put :: s -> m ()

    Replace the state inside the monad.

  • state :: (s -> (a, s)) -> m a

    Embed a simple state action into the monad.

Instances24MonadState, …