Equations
- instMonadEST ε σ = inferInstanceAs (Monad (EStateM ε σ))
Equations
- instMonadExceptOfEST ε σ = inferInstanceAs (MonadExceptOf ε (EStateM ε σ))
Equations
- instInhabitedEST = inferInstanceAs (Inhabited (EStateM ε σ α))
Equations
- instMonadST σ = inferInstanceAs (Monad (EST Empty σ))
Mutable reference cells that contain values of type α
. These cells can read from and mutated in
the ST σ
monad.
- ref : RefPointed.type
- h : Nonempty α
Instances For
Equations
- ST.Prim.Ref.modifyUnsafe r f = do let v ← ST.Prim.Ref.take r ST.Prim.Ref.set r (f v)
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
Equations
- ST.Prim.Ref.modify r f = do let v ← ST.Prim.Ref.get r ST.Prim.Ref.set r (f v)
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
Replaces the value of a mutable reference.
Equations
- r.set a = liftM (ST.Prim.Ref.set r a)
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)
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)
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)
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)
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)
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.