GHC.ST (original) (raw)

Synopsis

Documentation

newtype ST s a Source #

The strict [ST](GHC-ST.html#t:ST "GHC.ST") monad. The [ST](GHC-ST.html#t:ST "GHC.ST") monad allows for destructive updates, but is escapable (unlike IO). A computation of type `[ST](GHC-ST.html#t:ST "GHC.ST")` s a returns a value of type a, and execute in "thread" s. The s parameter is either

It serves to keep the internal states of different invocations of [runST](GHC-ST.html#v:runST "GHC.ST") separate from each other and from invocations of[stToIO](Control-Monad-ST.html#v:stToIO "Control.Monad.ST").

The [>>=](Control-Monad.html#v:-62--62--61- "Control.Monad") and [>>](Control-Monad.html#v:-62--62- "Control.Monad") operations are strict in the state (though not in values stored in the state). For example,

[runST](GHC-ST.html#v:runST "GHC.ST") (writeSTRef | v >>= f) = |

runST :: (forall s. ST s a) -> a Source #

Return the value computed by a state thread. The forall ensures that the internal state used by the [ST](GHC-ST.html#t:ST "GHC.ST") computation is inaccessible to the rest of the program.

Unsafe functions