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

Copyright | Josef Svenningsson 2008-2010 (c) The University of Glasgow, 1994-2000
License | BSD
Maintainer | josef.svenningsson@gmail.com
Stability | experimental
Portability | non-portable (GHC Extensions)
Safe Haskell | None
Language | Haskell98

Control.Monad.ST.Trans

Contents

- The ST Monad Transformer
- Mutable references
- Mutable arrays
- Unsafe Operations

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

- data STT s m a
- runST :: Monad m => (forall s. STT s m a) -> m a
- data STRef s a
- newSTRef :: Monad m => a -> STT s m (STRef s a)
- readSTRef :: Monad m => STRef s a -> STT s m a
- writeSTRef :: Monad m => STRef s a -> a -> STT s m ()
- data STArray s i e
- newSTArray :: (Ix i, Monad m) => (i, i) -> e -> STT s m (STArray s i e)
- readSTArray :: (Ix i, Monad m) => STArray s i e -> i -> STT s m e
- writeSTArray :: (Ix i, Monad m) => STArray s i e -> i -> e -> STT s m ()
- boundsSTArray :: STArray s i e -> (i, i)
- numElementsSTArray :: STArray s i e -> Int
- freezeSTArray :: (Ix i, Monad m) => STArray s i e -> STT s m (Array i e)
- thawSTArray :: (Ix i, Monad m) => Array i e -> STT s m (STArray s i e)
- runSTArray :: (Ix i, Monad m) => (forall s. STT s m (STArray s i e)) -> m (Array i e)
- unsafeIOToSTT :: Monad m => IO a -> STT s m a
- unsafeSTToIO :: STT s IO a -> IO a
- unsafeSTRefToIORef :: STRef s a -> IORef a
- unsafeIORefToSTRef :: IORef a -> STRef s a

# The ST Monad Transformer

data STT s m a Source

`STT` is the monad transformer providing polymorphic updateable references

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

Executes a computation in the `STT` monad transformer

# Mutable references

data STRef s a Source

Mutable references

Instances

Eq (STRef s a) Source |

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

Create a new reference

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

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) Source |

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 e Source

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 -> Int Source

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.

# Unsafe Operations

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

unsafeSTToIO :: STT s IO a -> IO a Source

unsafeSTRefToIORef :: STRef s a -> IORef a Source

unsafeIORefToSTRef :: IORef a -> STRef s a Source