HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulerebase-1.21.2Haskell2010

Rebase.Control.Monad.ST.Lazy

  • 2 types
  • 5 values
  • Packagerebase-1.21.2
  • Exports7
  • LanguageHaskell2010
  • LicenceMIT
  • SourceImp.hs
newtypenewtype ST s a
#

The lazy 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 executes 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 not strict in the state. For example,

runST (writeSTRef _|_ v >>= readSTRef _|_ >> return 2) = 2
Instances10Monad, Functor, MonadFix, Applicative, PrimBase, PrimMonad, …
  • Monad (ST s)Defined in ghc-internal-9.1003.0 · GHC.Internal.Control.Monad.ST.Lazy.Imp
  • Functor (ST s)Defined in ghc-internal-9.1003.0 · GHC.Internal.Control.Monad.ST.Lazy.Imp
  • MonadFix (ST s)Defined in ghc-internal-9.1003.0 · GHC.Internal.Control.Monad.ST.Lazy.Imp
  • Applicative (ST s)Defined in ghc-internal-9.1003.0 · GHC.Internal.Control.Monad.ST.Lazy.Imp
  • PrimBase (ST s)Defined in primitive-0.9.1.0 · Control.Monad.Primitive
  • PrimMonad (ST s)Defined in primitive-0.9.1.0 · Control.Monad.Primitive
  • Invariant (ST s)Defined in invariant-0.6.4 · Data.Functor.Invariant
  • MArray (STArray s) e (ST s)Defined in array-0.5.8.0 · Data.Array.Base
  • MonadBase (ST s) (ST s)Defined in transformers-base-0.4.6 · Control.Monad.Base
  • type PrimState (ST s) = sDefined in primitive-0.9.1.0 · Control.Monad.Primitive
datadata RealWorld
#

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#.

valuefixST :: (a -> ST s a) -> ST s a
#

Allow the result of an ST computation to be used (lazily) inside the computation. Note that if f is strict, fixST f = _|_.

valuerunST :: (forall s. ST s a) -> a
#

Return the value computed by an ST computation. The forall ensures that the internal state used by the ST computation is inaccessible to the rest of the program.

valuestToIO :: ST RealWorld a -> IO a
#

A monad transformer embedding lazy ST in the IO monad. 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.

valuestrictToLazyST :: ST s a -> ST s a
#

Convert a strict ST computation into a lazy one. The strict state thread passed to strictToLazyST is not performed until the result of the lazy state thread it returns is demanded.