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

GHC 10.0.0.20260917 · lts/ghc-10.0.x · fc4e598 · 2026-10-11

Moduleeffectful-core-2.7.1.2GHC2021

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:

Example3 expressions
import Control.Exception (ErrorCall)import Control.Monad.Catchimport Control.Monad.Trans.State.Strict qualified 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. :: HasCallStack
  2. => s

    The initial state.

  3. -> Eff (State s ': es) a
  4. -> 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. :: HasCallStack
  2. => s

    The initial state.

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

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

valueexecState
  1. :: HasCallStack
  2. => s

    The initial state.

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

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

Operations

valuestate
  1. :: (HasCallStack, 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.

valuestateM
  1. :: (HasCallStack, State s :> es)
  2. => (s -> Eff es (a, s))

    The function to modify the state.

  3. -> Eff es a
#

Deprecated. State modifications made via operations of the same State effect within the callback are discarded. Use a combination of get and put instead.

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

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

    The monadic function to modify the state.

  3. -> Eff es ()
#

Deprecated. State modifications made via operations of the same State effect within the callback are discarded. Use a combination of get and put instead.

Apply the monadic function to the current state.

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