stt-0.2.0.0: A monad transformer version of the ST monad

Portabilitynon-portable (GHC Extensions)
Stabilityexperimental
Maintainermckean.kylej@gmail.com
Safe HaskellNone

Control.Monad.Trans.ST

Contents

Description

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 will be duplicated across the different answers and this cause 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.

Synopsis

The ST Monad Transformer

data STT s m a

STT is the monad transformer providing polymorphic updateable references

Instances

MonadError e m => MonadError e (STT s m) 
MonadReader r m => MonadReader r (STT s m) 
MonadState s m => MonadState s (STT s' m) 
MonadWriter w m => MonadWriter w (STT s m) 
MonadTrans (STT s) 
Monad m => Monad (STT s m) 
Functor m => Functor (STT s m) 
MonadFix m => MonadFix (STT s m) 
(Monad m, Functor m) => Applicative (STT s m) 
Monad m => PrimMonad (STT s m) 

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

Executes a computation in the STT monad transformer

fixSTT :: MonadFix m => (a -> STT s m a) -> STT s m a

Allow the result of a state transformer computation to be used (lazily) inside the computation. Note that if f is strict, fixSTT f = _|_.

Mutable references

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

Create a new reference

readSTTRef :: Monad m => STRef s a -> STT s m a

Reads the value of a reference

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

Modifies the value of a reference

Mutable arrays

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

Creates a new mutable array

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

Retrieves an element from the array

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

Modifies an element in the array

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

Copy a mutable array and turn it into an immutable array

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

Copy an immutable array and turn it into a mutable array

runSTTArray :: (Ix i, Monad m) => (forall s. STT s m (STArray s i e)) -> 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

unsafeIOToSTT :: Monad m => IO a -> STT s m a

unsafeSTToIO :: STT s IO a -> IO a