HORIZON HASKELLDocslts/ghc-10.0.x8fef28d2026-11-02Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8fef28d · 2026-11-02

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!"
Contents
  1. Effect
  2. Handlers
  3. Operations
Synopsis

Effect

datadata State s (a :: Type -> Type) b

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

Instances2DispatchOf, StaticRep

Handlers

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)