Navigation

State

Mutable state effect: get/put/modify with standard handler.

get

get: read the current state threaded by the state handler; impure request whose response IS the handler state.

get : Computation s

Read the current state. Returns a Computation that, when handled, yields the current state value.

gets

gets: read a projection of the current state via a user function; sugar for bind get (s: pure (f s)).

gets : (s -> a) -> Computation a

Read a projection of the current state.

handler

state.handler: interprets get/put/modify over a single state value; pair with trampoline.handle and the initial state.

Standard state handler. Interprets get/put/modify effects. Use with trampoline.handle:

handle { handlers = state.handler; state = initialState; } comp
  • get: returns current state as value
  • put: replaces state with param, returns null
  • modify: applies param (a function) to state, returns null

modify

modify: apply a function to the current state in place; impure request resuming with null after the handler runs the transformer.

modify : (s -> s) -> Computation null

Apply a function to the current state. Returns a Computation that, when handled, transforms the state via f and returns null.

put

put: replace the current state with the supplied value; impure request resuming with null.

put : s -> Computation null

Replace the current state. Returns a Computation that, when handled, sets the state to the given value and returns null.

update

update: read the state, run a user computation against it to produce { state, value }, put the new state, return the value.

update : (s -> Computation { state, value }) -> Computation value

Apply a computation to the current state. Returns a Computation that, when handled, updates the state and returns value.