HORIZON HASKELLDocslts/ghc-9.14.x3e2d5682026-10-11Search names, modules, packages, or :: a typeCtrl K

GHC 9.14.1 · lts/ghc-9.14.x · 3e2d568 · 2026-10-11

Moduleextensible-effects-5.0.0.1Haskell2010

Control.Eff.State.Strict

Strict state effect

  • 2 types
  • 10 values
datadata State s v where
#

State, strict

Initial design: The state request carries with it the state mutator function We can use this request both for mutating and getting the state. But see below for a better design!

data State s v where
  State :: (s->s) -> State s s

In this old design, we have assumed that the dominant operation is modify. Perhaps this is not wise. Often, the reader is most nominant.

See also below, for decomposing the State into Reader and Writer!

The conventional design of State

Constructors

Instances3MonadBaseControl, Handle, StM
  • (MonadBase m m, LiftedBase m r) => MonadBaseControl m (Eff (State s ': r))Defined in extensible-effects-5.0.0.1 · Control.Eff.State.Strict
  • Handle (State s) r a (s -> k)Defined in extensible-effects-5.0.0.1 · Control.Eff.State.Strict

    Handle 'State s' requests

  • type StM (Eff (State s ': r)) a = StM (Eff r) (a, s)Defined in extensible-effects-5.0.0.1 · Control.Eff.State.Strict
valuewithState :: Monad m => a -> s -> m (a, s)
#

Embed a pure value in a stateful computation, i.e., given an initial state, how to interpret a pure value in a stateful computation.

valueget :: Member (State s) r => Eff r s
#

Return the current value of the state. The signatures are inferred

valuerunState
  1. :: s

    Initial state

  2. -> Eff (State s ': r) a

    Effect incorporating State

  3. -> Eff r (a, s)

    Effect containing final state and a return value

#

Run a State effect

valueevalState :: s -> Eff (State s ': r) a -> Eff r a
#

Run a State effect, discarding the final state.

valueexecState :: s -> Eff (State s ': r) a -> Eff r s
#

Run a State effect and return the final state.

datadata TxState (s :: k)
#

An encapsulated State handler, for transactional semantics The global state is updated only if the transactionState finished successfully

valuerunStateR :: s -> Eff (Writer s ': Reader s ': r) a -> Eff r (a, s)
#

A different representation of State: decomposing State into mutation (Writer) and Reading. We don't define any new effects: we just handle the existing ones. Thus we define a handler for two effects together.