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

Moduleextensible-effects-5.0.0.1Haskell2010

Control.Eff.State.Lazy

Lazy state effect

Synopsis
datadata State s v where

State, lazy

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.Lazy
  • Handle (State s) r a (s -> k)Defined in extensible-effects-5.0.0.1 · Control.Eff.State.Lazy

    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.Lazy
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.

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

datadata TxState (s :: k) (v :: k) where

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

Constructors

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.