HORIZON HASKELLDocslts/ghc-10.0.x77a86622026-10-31Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 77a8662 · 2026-10-31

Modulerio-0.1.25.0Haskell2010

RIO.State

Provides reexports of MonadState and related helpers.

Synopsis
  • Packagerio-0.1.25.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.

Instances18MonadState, …
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.

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, …