Control.Monad.ST
- Package
- purescript-st
- Repository
- purescript/purescript-st
#ST Source
data ST :: Type -> Effect
The ST
effect represents local mutation, i.e. mutation which does not
"escape" into the surrounding computation.
An ST
computation is parameterized by a phantom type which is used to
restrict the set of reference cells it is allowed to access.
The runST
function can be used to handle the ST
effect.
#modifySTRef Source
modifySTRef :: forall r h a. STRef h a -> (a -> a) -> Eff (st :: ST h | r) a
Modify the value of a mutable reference by applying a function to the current value.
#writeSTRef Source
writeSTRef :: forall r h a. STRef h a -> a -> Eff (st :: ST h | r) a
Set the value of a mutable reference.
#runST Source
runST :: forall r a. (forall h. Eff (st :: ST h | r) a) -> Eff r a
Run an ST
computation.
Note: the type of runST
uses a rank-2 type to constrain the phantom
type h
, such that the computation must not leak any mutable references
to the surrounding computation.
It may cause problems to apply this function using the $
operator. The
recommended approach is to use parentheses instead.
#pureST Source
pureST :: forall a. (forall h. Eff (st :: ST h) a) -> a
A convenience function which combines runST
with runPure
, which can be
used when the only required effect is ST
.
Note: since this function has a rank-2 type, it may cause problems to apply
this function using the $
operator. The recommended approach is to use
parentheses instead.
- Modules
- Control.
Monad. ST