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

Modulerio-0.1.22.0Haskell2010

RIO.State

Provides reexports of MonadState and related helpers.

  • 2 types
  • 1 class
  • 12 values
  • Packagerio-0.1.22.0
  • Exports15
  • LanguageHaskell2010
  • LicenceMIT
  • SourceState.hs
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.

Instances17MonadState, …
valuegets :: MonadState s m => (s -> a) -> m a
#

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

valuemodify :: MonadState s m => (s -> s) -> m ()
#

Monadic state transformer.

Maps an old state to a new state inside a state monad. The old state is thrown away.

     Main> :t modify ((+1) :: Int -> Int)
     modify (...) :: (MonadState Int a) => a ()

This says that modify (+1) acts over any Monad that is a member of the MonadState class, with an Int state.

valuemodify' :: MonadState s m => (s -> s) -> m ()
#

A variant of modify in which the computation is strict in the new state.

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.

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

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.

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

Instances26MonadAccum, MonadError, MonadReader, MonadState, MonadWriter, MonadSelect, …