STMonadTrans-0.1: A monad transformer version of the ST monad

Portabilitynon-portable (GHC Extensions)
Stabilityexperimental
Maintainerjosef.svenningsson@gmail.com

Control.Monad.ST.Trans

Contents

Description

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

Synopsis

The ST Monad Transformer

data STT s m a Source

STT is the monad transformer providing polymorphic updateable references

Instances

MonadReader r m => MonadReader r (STT s m) 
MonadState s m => MonadState s (STT s' m) 
MonadError e m => MonadError e (STT s m) 
MonadWriter w m => MonadWriter w (STT s m) 
MonadTrans (STT s) 
Monad m => Monad (STT s m) 

runST :: Monad m => (forall s. STT s m a) -> m aSource

Executes a computation in the STT monad transformer

Mutable references

data STRef s a Source

Mutable references

Instances

Eq (STRef s a) 

newSTRef :: Monad m => a -> STT s m (STRef s a)Source

Create a new reference

readSTRef :: Monad m => STRef s a -> STT s m aSource

Reads the value of a reference

writeSTRef :: Monad m => STRef s a -> a -> STT s m ()Source

Modifies the value of a reference

Mutable arrays

data STArray s i e Source

Mutable arrays

Instances

Eq (STArray s i e) 

newSTArray :: (Ix i, Monad m) => (i, i) -> e -> STT s m (STArray s i e)Source

Creates a new mutable array

readSTArray :: (Ix i, Monad m) => STArray s i e -> i -> STT s m eSource

Retrieves an element from the array

writeSTArray :: (Ix i, Monad m) => STArray s i e -> i -> e -> STT s m ()Source

Modifies an element in the array

boundsSTArray :: STArray s i e -> (i, i)Source

Returns the lowest and highest indices of the array

numElementsSTArray :: STArray s i e -> IntSource

Returns the number of elements in the array

freezeSTArray :: (Ix i, Monad m) => STArray s i e -> STT s m (Array i e)Source

Copy a mutable array and turn it into an immutable array

thawSTArray :: (Ix i, Monad m) => Array i e -> STT s m (STArray s i e)Source

Copy an immutable array and turn it into a mutable array

runSTArray :: (Ix i, Monad m) => (forall s. STT s m (STArray s i e)) -> m (Array i e)Source

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.