std.effect.state

Implementation of the State effect

Types

type State s r a = 
    | Get : State s r s
    | Put : s -> State s r ()
    .. r

The State effect provides an updatable state

Values

let get : forall r . forall s . Eff [| state : State s | r |] s

Retreive the current value.

let gets f : forall r a . forall s . (s -> a) -> Eff [| state : State s | r |] a

Retreive the current value and applied f to it.

let put s : forall r s . s -> Eff [| state : State s | r |] ()

Store s as the new value of the state.

let modify f : forall r s . (s -> s) -> Eff [| state : State s | r |] ()

Update the state by applying f.

let run_state s eff : forall a r .
        forall s .
            s
                -> Eff [| state : State s | r |] a
                -> Eff [| | r |] { state : s, value : a }

Eliminate the State effect and return the state and the computed value

let exec_state s eff : forall a r . forall s . s -> Eff [| state : State s | r |] a -> Eff [| | r |] s

Eliminate the State effect and return the state

let eval_state s eff : forall a r . forall s . s -> Eff [| state : State s | r |] a -> Eff [| | r |] a

Eliminate the State effect and return the computed value