ST Monad

The ST monad allows in-place updates, but is escapable, meaning some values in the internal context can be returned. The type signature is

ST Monad
1
ST s a

The type signature means that they returns a value of type a and is executed in the context s.

The most important method is runST, basically, it executes a ST monad and gets the returned value.

runST
1
runST :: forall a. (forall s. ST s a) -> a

In-place Operations

References/variables that can be used within the ST monad are provided in Data.STRef and arrays are in Data.Array.ST

Data.STRef

Methods
1
2
3
4
5
6
-- a value of `STRef s a` is a mutable variable
-- in the state thread `s` and contains a value of type `a`
data STRef s a

-- creates a reference variable
newSTRef :: a -> ST s (STRef s a)