The state threaded through the computation.
The value the computation yields.
Let yield* bind this State inside a do block: yields this State and
returns the value the block is resumed with.
It exists for yield*, not for spreading: [...state] is a one-element
array holding this State itself, and does not run it.
A generator that yields this State once.
Return a function that runs the computation from a given state, for callers that want to run it later or pass it where a plain function is expected.
Haskell's runState used unapplied, as a function s -> (a, s).
A function from an initial state to [result, finalState].
StaticdoBuild a State from a do block: Haskell's do notation, with
x <- m written const x = yield* m.
Each yield* m runs m against the state the previous step left and
binds its value, typed with no annotation. The state type S is inferred
from the States the block yields, and every one must share it. Nothing in
the block runs until run(), eval() or exec(), and every run starts
the block afresh. A throw in the block is thrown from that call. A plain
yield (without *) binds unknown; use yield*.
The state type; inferred from the yielded States.
The value the block returns.
A State that runs the block and yields what it returns.
StaticgetStaticgetsStaticmodifyStaticofStaticput
A computation that takes a state of type
Sand yields a value of typeAtogether with the next state.Nothing runs until
run(),eval()orexec()is called with an initial state, so a State can be built once and run against many starting states.A throw in a caller-supplied function is thrown from
run(),eval()orexec(), not from the call that built the State.Example