Safe Haskell | None |
---|---|
Language | Haskell2010 |
An effect that adds a mutable, updatable state value to a given computation.
Not all computations require a full-fledged state effect: read-only state is better served by Reader
, and append-only state without reads is better served by Writer
.
Predefined carriers:
- Control.Carrier.State.Strict, which is strict in its updates.
- Control.Carrier.State.Lazy, which is lazy in its updates. This enables more programs to terminate, such as cyclic computations expressed with
MonadFix
or-XRecursiveDo
, at the cost of efficiency. - Control.Monad.Trans.RWS.Lazy
- Control.Monad.Trans.RWS.Strict
- Control.Monad.Trans.State.Lazy
- Control.Monad.Trans.State.Strict
Since: 0.1.0.0
Synopsis
- data State s m k
- get :: Has (State s) sig m => m s
- gets :: Has (State s) sig m => (s -> a) -> m a
- put :: Has (State s) sig m => s -> m ()
- modify :: Has (State s) sig m => (s -> s) -> m ()
- modifyLazy :: Has (State s) sig m => (s -> s) -> m ()
- class (HFunctor sig, Monad m) => Algebra sig m | m -> sig
- type Has eff sig m = (Members eff sig, Algebra sig m)
- run :: Identity a -> a
State effect
Since: 0.1.0.0
Instances
modifyLazy :: Has (State s) sig m => (s -> s) -> m () Source #
Replace the state value with the result of applying a function to the current state value. This is lazy in the new state; injudicious use of this function may lead to space leaks.
modifyLazy
f =get
>>=
put
. f
Since: 0.3.0.0
Re-exports
class (HFunctor sig, Monad m) => Algebra sig m | m -> sig Source #
The class of carriers (results) for algebras (effect handlers) over signatures (effects), whose actions are given by the alg
method.
Since: 1.0.0.0
Instances
type Has eff sig m = (Members eff sig, Algebra sig m) Source #
m
is a carrier for sig
containing eff
.
Note that if eff
is a sum, it will be decomposed into multiple Member
constraints. While this technically allows one to combine multiple unrelated effects into a single Has
constraint, doing so has two significant drawbacks:
- Due to a problem with recursive type families, this can lead to significantly slower compiles.
- It defeats
ghc
’s warnings for redundant constraints, and thus can lead to a proliferation of redundant constraints as code is changed.