HORIZON HASKELLDocslts/ghc-10.0.x8fef28d2026-11-02Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8fef28d · 2026-11-02

Moduleadjunctions-4.4.4Haskell2010

Control.Monad.Representable.State

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

Synopsis
  • Packageadjunctions-4.4.4
  • 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.

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

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.

Instances25MonadState, …