Control.Monad.ST.Safe



Copyright
(c) The University of Glasgow 2001


License
BSD-style (see the file libraries/base/LICENSE)


Maintainer
tamara19@example.net


Stability
stable


Portability
non-portable (requires universal quantification for runST)


Safe Haskell
Trustworthy


Language
Haskell2010



Contents

The ST Monad
Converting ST to IO



Description
Deprecated: Safe is now the default, please use Control.Monad.ST instead
This library provides support for strict state threads, as described in the PLDI '94 paper by John Launchbury and Simon Peyton Jones Lazy Functional State Threads.
Safe API Only.

The ST Monaddata ST s a Source 
The strict ST monad. The ST monad allows for destructive updates, but is escapable (unlike IO). A computation of type 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), or

RealWorld (inside invocations of stToIO).

It serves to keep the internal states of different invocations of runST separate from each other and from invocations of stToIO.
The >>= and >> operations are strict in the state (though not in values stored in the state). For example,
runST (writeSTRef _|_ v >>= f) = _|_

Instances
Instances details


MonadFix (ST s) Source 
Since: base-2.1

Instance detailsDefined in Control.Monad.Fix 
Methods
mfix 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (a -> ST s a) -> ST s a Source 



Applicative (ST s) Source 
Since: base-208-500-1805

Instance detailsDefined in GHC.ST 
Methods
pure 8b7c:f320:99b9:690f:4595:cd17:293a:c069 a -> ST s a Source 
(<*>) 8b7c:f320:99b9:690f:4595:cd17:293a:c069 ST s (a -> b) -> ST s a -> ST s b Source 
liftA2 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (a -> b -> c) -> ST s a -> ST s b -> ST s c Source 
(*>) 8b7c:f320:99b9:690f:4595:cd17:293a:c069 ST s a -> ST s b -> ST s b Source 
(<*) 8b7c:f320:99b9:690f:4595:cd17:293a:c069 ST s a -> ST s b -> ST s a Source 



Functor (ST s) Source 
Since: base-2.1

Instance detailsDefined in GHC.ST 
Methods
fmap 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (a -> b) -> ST s a -> ST s b Source 
(<$) 8b7c:f320:99b9:690f:4595:cd17:293a:c069 a -> ST s b -> ST s a Source 



Monad (ST s) Source 
Since: base-2.1

Instance detailsDefined in GHC.ST 
Methods
(>>=) 8b7c:f320:99b9:690f:4595:cd17:293a:c069 ST s a -> (a -> ST s b) -> ST s b Source 
(>>) 8b7c:f320:99b9:690f:4595:cd17:293a:c069 ST s a -> ST s b -> ST s b Source 
return 8b7c:f320:99b9:690f:4595:cd17:293a:c069 a -> ST s a Source 



Monoid a => Monoid (ST s a) Source 
Since: base-208-500-1805

Instance detailsDefined in GHC.ST 
Methods
mempty 8b7c:f320:99b9:690f:4595:cd17:293a:c069 ST s a Source 
mappend 8b7c:f320:99b9:690f:4595:cd17:293a:c069 ST s a -> ST s a -> ST s a Source 
mconcat 8b7c:f320:99b9:690f:4595:cd17:293a:c069 [ST s a] -> ST s a Source 



Semigroup a => Semigroup (ST s a) Source 
Since: base-208-500-1805

Instance detailsDefined in GHC.ST 
Methods
(<>) 8b7c:f320:99b9:690f:4595:cd17:293a:c069 ST s a -> ST s a -> ST s a Source 
sconcat 8b7c:f320:99b9:690f:4595:cd17:293a:c069 NonEmpty (ST s a) -> ST s a Source 
stimes 8b7c:f320:99b9:690f:4595:cd17:293a:c069 Integral b => b -> ST s a -> ST s a Source 



Show (ST s a) Source 
Since: base-2.1

Instance detailsDefined in GHC.ST 
Methods
showsPrec 8b7c:f320:99b9:690f:4595:cd17:293a:c069 Int -> ST s a -> ShowS Source 
show 8b7c:f320:99b9:690f:4595:cd17:293a:c069 ST s a -> String Source 
showList 8b7c:f320:99b9:690f:4595:cd17:293a:c069 [ST s a] -> ShowS Source 



runST 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (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 computation is inaccessible to the rest of the program.
fixST 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (a -> ST s a) -> ST s a Source 
Allow the result of an ST computation to be used (lazily) inside the computation.
Note that if f is strict, fixST f = _|_.
Converting ST to IOdata RealWorld Source 
RealWorld is deeply magical. It is primitive, but it is not unlifted (hence ptrArg). We never manipulate values of type RealWorld; it's only used in the type system, to parameterise State#. 
stToIO 8b7c:f320:99b9:690f:4595:cd17:293a:c069 ST RealWorld a -> IO a Source 
Embed a strict state thread in an IO action. The RealWorld parameter indicates that the internal state used by the ST computation is a special one supplied by the IO monad, and thus distinct from those used by invocations of runST.


    
{'path': 'public/docs/haskell~9/libraries/base-4.17.0.0/control-monad-st-safe.html', 'source': 'DevDocs.IO'}