Equations
- instMonadEST ε σ = inferInstanceAs (Monad (EStateM ε σ))
Equations
- instMonadExceptOfEST ε σ = inferInstanceAs (MonadExceptOf ε (EStateM ε σ))
Equations
- instInhabitedEST = inferInstanceAs (Inhabited (EStateM ε σ α))
Equations
- instMonadST σ = inferInstanceAs (Monad (EST Empty σ))
Runs an EST
computation, in which mutable state and exceptions are the only side effects.
Equations
- runEST x = match x Unit () with | EStateM.Result.ok a a_1 => Except.ok a | EStateM.Result.error ex a => Except.error ex
Instances For
Equations
- ST.Prim.Ref.modifyUnsafe r f = do let v ← ST.Prim.Ref.take r ST.Prim.Ref.set r (f v)
Instances For
Equations
- ST.Prim.Ref.modifyGetUnsafe r f = do let v ← ST.Prim.Ref.take r match f v with | (b, a) => do ST.Prim.Ref.set r a pure b
Instances For
Equations
- ST.Prim.Ref.modify r f = do let v ← ST.Prim.Ref.get r ST.Prim.Ref.set r (f v)
Instances For
Equations
- ST.Prim.Ref.modifyGet r f = do let v ← ST.Prim.Ref.get r match f v with | (b, a) => do ST.Prim.Ref.set r a pure b
Instances For
Reads the value of a mutable reference.
Equations
- r.get = liftM (ST.Prim.Ref.get r)
Instances For
Replaces the value of a mutable reference.
Equations
- r.set a = liftM (ST.Prim.Ref.set r a)
Instances For
Atomically swaps the value of a mutable reference cell with another value. The reference cell's original value is returned.
Equations
- r.swap a = liftM (ST.Prim.Ref.swap r a)
Instances For
Reads the value of a mutable reference cell, removing it.
This causes subsequent attempts to read from or take the reference cell to block until a new value
is written using ST.Ref.set
.
Equations
- r.take = liftM (ST.Prim.Ref.take r)
Instances For
Checks whether two reference cells are in fact aliases for the same cell.
Even if they contain the same value, two references allocated by different executions of IO.mkRef
or ST.mkRef
are distinct. Modifying one has no effect on the other. Likewise, a single reference
cell may be aliased, and modifications to one alias also modify the other.
Equations
- r1.ptrEq r2 = liftM (ST.Prim.Ref.ptrEq r1 r2)
Instances For
Atomically modifies a mutable reference cell by replacing its contents with the result of a function call.
Equations
- r.modify f = liftM (ST.Prim.Ref.modify r f)
Instances For
Atomically modifies a mutable reference cell by replacing its contents with the result of a function call that simultaneously computes a value to return.
Equations
- r.modifyGet f = liftM (ST.Prim.Ref.modifyGet r f)
Instances For
Creates a MonadStateOf
instance from a reference cell.
This allows programs written against the state monad API to be executed using a mutable reference cell to track the state.