HORIZON HASKELLDocslts/ghc-10.0.x2b276322026-10-31Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 2b27632 · 2026-10-31

Moduleghc-internal-10.0.0Haskell2010

GHC.Internal.ST

The ST Monad.

Contents
  1. Unsafe functions
Synopsis
newtypenewtype ST s a

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) = _|_

Constructors

Instances7Monad, Functor, MonadFix, Applicative, Show, Semigroup, …
  • Monad (ST s)Defined in ghc-internal-10.0.0 · GHC.Internal.ST
  • Functor (ST s)Defined in ghc-internal-10.0.0 · GHC.Internal.ST
  • MonadFix (ST s)Defined in ghc-internal-10.0.0 · GHC.Internal.Control.Monad.Fix
  • Applicative (ST s)Defined in ghc-internal-10.0.0 · GHC.Internal.ST
  • Show (ST s a)Defined in ghc-internal-10.0.0 · GHC.Internal.ST
  • Semigroup a => Semigroup (ST s a)Defined in ghc-internal-10.0.0 · GHC.Internal.ST
  • Monoid a => Monoid (ST s a)Defined in ghc-internal-10.0.0 · GHC.Internal.ST
valuerunST :: (forall s. ST s a) -> a

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.

Unsafe functions