HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Moduleeffectful-core-2.3.0.1Haskell2010

Effectful.State.Static.Local

Support for access to a mutable value of a particular type.

The value is thread local. If you want it to be shared between threads, use Effectful.State.Static.Shared.

Note: unlike the Control.Monad.Trans.State.StateT monad transformer from the transformers library, the State effect doesn't discard state updates when an exception is received:

Example1 expression
import qualified Control.Monad.Trans.State.Strict as S
Example1 expression
:{  (`S.execStateT` "Hi") . handle (\(_::ErrorCall) -> pure ()) $ do    S.modify (++ " there!")    error "oops":}"Hi"
Example1 expression
:{  runEff . execState "Hi" . handle (\(_::ErrorCall) -> pure ()) $ do    modify (++ " there!")    error "oops":}"Hi there!"
  • 1 type
  • 10 values

Effect

1 declaration
datadata State s (a :: Type -> Type) b
#

Provide access to a strict (WHNF), thread local, mutable value of type s.

Instances2DispatchOf, StaticRep

Handlers

valuerunState
  1. :: s

    The initial state.

  2. -> Eff (State s ': es) a
  3. -> Eff es (a, s)
#

Run the State effect with the given initial state and return the final value along with the final state.

valueevalState
  1. :: s

    The initial state.

  2. -> Eff (State s ': es) a
  3. -> Eff es a
#

Run the State effect with the given initial state and return the final value, discarding the final state.

valueexecState
  1. :: s

    The initial state.

  2. -> Eff (State s ': es) a
  3. -> Eff es s
#

Run the State effect with the given initial state and return the final state, discarding the final value.

Operations

valueget :: State s :> es => Eff es s
#

Fetch the current value of the state.

valuegets
  1. :: State s :> es
  2. => (s -> a)

    The function to apply to the state.

  3. -> Eff es a
#

Get a function of the current state.

gets f ≡ f <$> get
valueput :: State s :> es => s -> Eff es ()
#

Set the current state to the given value.

valuestate
  1. :: State s :> es
  2. => (s -> (a, s))

    The function to modify the state.

  3. -> Eff es a
#

Apply the function to the current state and return a value.

valuemodify
  1. :: State s :> es
  2. => (s -> s)

    The function to modify the state.

  3. -> Eff es ()
#

Apply the function to the current state.

modify f ≡ state (\s -> ((), f s))
valuestateM
  1. :: State s :> es
  2. => (s -> Eff es (a, s))

    The function to modify the state.

  3. -> Eff es a
#

Apply the monadic function to the current state and return a value.

valuemodifyM
  1. :: State s :> es
  2. => (s -> Eff es s)

    The monadic function to modify the state.

  3. -> Eff es ()
#

Apply the monadic function to the current state.

modifyM f ≡ stateM (\s -> ((), ) <$> f s)