Module

Control.Monad.ST

Package
purescript-st
Repository
purescript/purescript-st

#STSource

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.

#STRefSource

data STRef :: Type -> Type -> Type

The type STRef h a represents a mutable reference holding a value of type a, which can be used with the ST h effect.

#newSTRefSource

newSTRef :: forall a h r. a -> Eff (st :: ST h | r) (STRef h a)

Create a new mutable reference.

#readSTRefSource

readSTRef :: forall a h r. STRef h a -> Eff (st :: ST h | r) a

Read the current value of a mutable reference.

#modifySTRefSource

modifySTRef :: forall a h r. 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.

#writeSTRefSource

writeSTRef :: forall a h r. STRef h a -> a -> Eff (st :: ST h | r) a

Set the value of a mutable reference.

#runSTSource

runST :: forall a r. (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.

#pureSTSource

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.