extensible-effects-2.2.1.0: An Alternative to Monad Transformers

Control.Eff.State.Lazy

Description

Lazy state effect

Synopsis

Documentation

data State s v where Source #

State, lazy (i.e., on-demand)

Extensible effects make it clear that where the computation is delayed (which I take as an advantage) and they do maintain the degree of extensibility (the delayed computation must be effect-closed, but the whole computation does not have to be).

Constructors

 Get :: State s s Put :: s -> State s () Delay :: Eff '[State s] a -> State s a

get :: Member (State s) r => Eff r s Source #

Return the current value of the state. The signatures are inferred

put :: Member (State s) r => s -> Eff r () Source #

Write a new value of the state.

onDemand :: Member (State s) r => Eff '[State s] v -> Eff r v Source #

runState' :: Eff (State s ': r) w -> s -> Eff r (w, s) Source #

Arguments

 :: Eff (State s ': r) w Effect incorporating State -> s Initial state -> Eff r (w, s) Effect containing final state and a return value

Run a State effect

modify :: Member (State s) r => (s -> s) -> Eff r () Source #

Transform the state with a function.

evalState :: Eff (State s ': r) w -> s -> Eff r w Source #

Run a State effect, discarding the final state.

execState :: Eff (State s ': r) w -> s -> Eff r s Source #

Run a State effect and return the final state.

runStateR :: Eff (Writer s ': (Reader s ': r)) w -> s -> Eff r (w, s) Source #

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.

runStateBack0 :: Eff '[State s] a -> (a, s) Source #

Backwards state The overall state is represented with two attributes: the inherited getAttr and the synthesized putAttr. At the root node, putAttr becomes getAttr, tying the knot. As usual, the inherited attribute is the argument (i.e., the environment) and the synthesized is the result of the handler |go| below.

runStateBack :: Eff '[State s] a -> (a, s) Source #

A different notion of backwards is realized if we change the Put handler slightly. How?

Another implementation, exploring Haskell's laziness to make putAttr also technically inherited, to accumulate the sequence of updates. This implementation is compatible with deep handlers, and lets us play with different notions of backwardness