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

ModuleSTMonadTrans-0.4.8Haskell2010

Control.Monad.ST.Trans

This library provides a monad transformer version of the ST monad.

Warning! This monad transformer should not be used with monads that can contain multiple answers, like the list monad. The reason is that the state token will be duplicated across the different answers and this causes Bad Things to happen (such as loss of referential transparency). Safe monads include the monads State, Reader, Writer, Maybe and combinations of their corresponding monad transformers.

  • 3 types
  • 22 values

The ST Monad Transformer

3 declarations
newtypenewtype STT s (m :: Type -> Type) a
#

STT is the monad transformer providing polymorphic updateable references

Instances30MonadError, MonadReader, MonadState, MonadWriter, MonadTrans, MArray, …
valuerunST :: Monad m => (forall s. STT s m a) -> m a
#

Deprecated. Use runSTT instead

Executes a computation in the STT monad transformer

valuerunSTT :: Monad m => (forall s. STT s m a) -> m a
#

Executes a computation in the STT monad transformer

Mutable references

4 declarations
datadata STRef s a
#

a value of type STRef s a is a mutable variable in state thread s, containing a value of type a

Example1 expression
:{runST (do    ref <- newSTRef "hello"    x <- readSTRef ref    writeSTRef ref (x ++ "world")    readSTRef ref ):}"helloworld"
Instances1Eq
  • Eq (STRef s a)Defined in ghc-internal-9.1003.0 · GHC.Internal.STRef

    Pointer equality.

Mutable arrays

9 declarations
datadata STArray s i e
#

Mutable, boxed, non-strict arrays in the ST monad. The type arguments are as follows:

  • s: the state variable argument for the ST type

  • i: the index type of the array (should be an instance of Ix)

  • e: the element type of the array.

Instances4MArray, Eq
valuerunSTArray
  1. :: Monad m
  2. => forall s. STT s m (STArray s i e)
  3. -> m (Array i e)
#

A safe way to create and work with a mutable array before returning an immutable array for later perusal. This function avoids copying the array before returning it.

Unsafe Operations

9 declarations