std.effect.st

Modules

std.effect.st.string

Implementation of the st.State effect

Types

type State s r a = 
    | New : forall b . b -> State s r (STRef s b)
    | Read : STRef s a -> State s r a
    | Write : forall b . b -> STRef s b -> State s r ()
    | Call : forall b . (() -> b) -> State s r b
    .. r

The State effect enables the use of mutable state. By branding the state with s the mutable values are prevented from escaping the monad.

Values

#[inline(never)]
let send_state f : forall a r . forall s . State s r a -> Eff [| st : State s | r |] a

let new_ref a : forall r a . forall s . a -> Eff [| st : State s | r |] (STRef s a)

Creates a new mutable reference that contains a.

let read_ref ref : forall r a . forall s . STRef s a -> Eff [| st : State s | r |] a

Reads the values stored in the reference.

let write_ref a ref : forall r a . forall s . a -> STRef s a -> Eff [| st : State s | r |] ()

Writes a new value into the reference.

let run_state eff : forall a r . (forall s . Eff [| st : State s | r |] a) -> Eff [| | r |] a

Eliminates the State effect

let make_call : forall a a0 a1 . (() -> a) -> State a0 a1 a