GHC.ST (original) (raw)
Synopsis
- newtype ST s a = ST (STRep s a)
- data STret s a = STret (State# s) a
- type STRep s a = State# s -> (# State# s, a #)
- runST :: (forall s. ST s a) -> a
- liftST :: ST s a -> State# s -> STret s a
- unsafeInterleaveST :: ST s a -> ST s a
- unsafeDupableInterleaveST :: ST s a -> ST s a
Documentation
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
- an uninstantiated type variable (inside invocations of
[runST](GHC-ST.html#v:runST "GHC.ST")), or [RealWorld](Control-Monad-ST-Safe.html#t:RealWorld "Control.Monad.ST.Safe")(inside invocations of[stToIO](Control-Monad-ST.html#v:stToIO "Control.Monad.ST")).
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.