Data.Array.ST.Safe

array-0.5.3.0: Mutable and immutable arrays

Copyright | (c) The University of Glasgow 2011
License | BSD-style (see the file libraries/base/LICENSE)
Maintainer | libraries@haskell.org
Stability | experimental
Portability | non-portable (uses Data.Array.MArray)
Safe Haskell | Trustworthy
Language | Haskell2010

Data.Array.ST.Safe

Contents

- Boxed arrays
- Unboxed arrays
- Overloaded mutable array interface

Description

Mutable boxed and unboxed arrays in the `ST` monad.

Safe API only of Data.Array.ST.

Since: array-0.4.0.0

Synopsis

- data STArray s i e
- runSTArray :: (forall s. ST s (STArray s i e)) -> Array i e
- data STUArray s i e
- runSTUArray :: (forall s. ST s (STUArray s i e)) -> UArray i e
- module Data.Array.MArray.Safe

# Boxed arrays

data STArray s i e Source #

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.

Instances

MArray (STArray s) e (ST s) # |
Instance details Defined in Data.Array.Base Methods getBounds :: Ix i => STArray s i e -> ST s (i, i) # getNumElements :: Ix i => STArray s i e -> ST s Int newArray :: Ix i => (i, i) -> e -> ST s (STArray s i e) # newArray_ :: Ix i => (i, i) -> ST s (STArray s i e) # unsafeNewArray_ :: Ix i => (i, i) -> ST s (STArray s i e) unsafeRead :: Ix i => STArray s i e -> Int -> ST s e unsafeWrite :: Ix i => STArray s i e -> Int -> e -> ST s ()
MArray (STArray s) e (ST s) # |
Instance details Defined in Data.Array.Base Methods getBounds :: Ix i => STArray s i e -> ST s (i, i) # getNumElements :: Ix i => STArray s i e -> ST s Int newArray :: Ix i => (i, i) -> e -> ST s (STArray s i e) # newArray_ :: Ix i => (i, i) -> ST s (STArray s i e) # unsafeNewArray_ :: Ix i => (i, i) -> ST s (STArray s i e) unsafeRead :: Ix i => STArray s i e -> Int -> ST s e unsafeWrite :: Ix i => STArray s i e -> Int -> e -> ST s ()
Eq (STArray s i e) | Since: base-2.1
Instance details Defined in GHC.Arr Methods (==) :: STArray s i e -> STArray s i e -> Bool # (/=) :: STArray s i e -> STArray s i e -> Bool #

runSTArray :: (forall s. ST s (STArray s i e)) -> 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 - it uses `unsafeFreeze` internally, but this wrapper is a safe interface to that function.

# Unboxed arrays

data STUArray s i e #

A mutable array with unboxed elements, that can be manipulated 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. Only certain element types are supported.

An `STUArray` will generally be more efficient (in terms of both time and space) than the equivalent boxed version (`STArray`) with the same element type. However, `STUArray` is strict in its elements - so don't use `STUArray` if you require the non-strictness that `STArray` provides.

Instances

MArray (STUArray s) Word64 (ST s) # |
Instance details Defined in Data.Array.Base Methods getBounds :: Ix i => STUArray s i Word64 -> ST s (i, i) # getNumElements :: Ix i => STUArray s i Word64 -> ST s Int newArray :: Ix i => (i, i) -> Word64 -> ST s (STUArray s i Word64) # newArray_ :: Ix i => (i, i) -> ST s (STUArray s i Word64) # unsafeNewArray_ :: Ix i => (i, i) -> ST s (STUArray s i Word64) unsafeRead :: Ix i => STUArray s i Word64 -> Int -> ST s Word64 unsafeWrite :: Ix i => STUArray s i Word64 -> Int -> Word64 -> ST s ()
MArray (STUArray s) Word32 (ST s) # |
Instance details Defined in Data.Array.Base Methods getBounds :: Ix i => STUArray s i Word32 -> ST s (i, i) # getNumElements :: Ix i => STUArray s i Word32 -> ST s Int newArray :: Ix i => (i, i) -> Word32 -> ST s (STUArray s i Word32) # newArray_ :: Ix i => (i, i) -> ST s (STUArray s i Word32) # unsafeNewArray_ :: Ix i => (i, i) -> ST s (STUArray s i Word32) unsafeRead :: Ix i => STUArray s i Word32 -> Int -> ST s Word32 unsafeWrite :: Ix i => STUArray s i Word32 -> Int -> Word32 -> ST s ()
MArray (STUArray s) Word16 (ST s) # |
Instance details Defined in Data.Array.Base Methods getBounds :: Ix i => STUArray s i Word16 -> ST s (i, i) # getNumElements :: Ix i => STUArray s i Word16 -> ST s Int newArray :: Ix i => (i, i) -> Word16 -> ST s (STUArray s i Word16) # newArray_ :: Ix i => (i, i) -> ST s (STUArray s i Word16) # unsafeNewArray_ :: Ix i => (i, i) -> ST s (STUArray s i Word16) unsafeRead :: Ix i => STUArray s i Word16 -> Int -> ST s Word16 unsafeWrite :: Ix i => STUArray s i Word16 -> Int -> Word16 -> ST s ()
MArray (STUArray s) Word8 (ST s) # |
Instance details Defined in Data.Array.Base Methods getBounds :: Ix i => STUArray s i Word8 -> ST s (i, i) # getNumElements :: Ix i => STUArray s i Word8 -> ST s Int newArray :: Ix i => (i, i) -> Word8 -> ST s (STUArray s i Word8) # newArray_ :: Ix i => (i, i) -> ST s (STUArray s i Word8) # unsafeNewArray_ :: Ix i => (i, i) -> ST s (STUArray s i Word8) unsafeRead :: Ix i => STUArray s i Word8 -> Int -> ST s Word8 unsafeWrite :: Ix i => STUArray s i Word8 -> Int -> Word8 -> ST s ()
MArray (STUArray s) Int64 (ST s) # |
Instance details Defined in Data.Array.Base Methods getBounds :: Ix i => STUArray s i Int64 -> ST s (i, i) # getNumElements :: Ix i => STUArray s i Int64 -> ST s Int newArray :: Ix i => (i, i) -> Int64 -> ST s (STUArray s i Int64) # newArray_ :: Ix i => (i, i) -> ST s (STUArray s i Int64) # unsafeNewArray_ :: Ix i => (i, i) -> ST s (STUArray s i Int64) unsafeRead :: Ix i => STUArray s i Int64 -> Int -> ST s Int64 unsafeWrite :: Ix i => STUArray s i Int64 -> Int -> Int64 -> ST s ()
MArray (STUArray s) Int32 (ST s) # |
Instance details Defined in Data.Array.Base Methods getBounds :: Ix i => STUArray s i Int32 -> ST s (i, i) # getNumElements :: Ix i => STUArray s i Int32 -> ST s Int newArray :: Ix i => (i, i) -> Int32 -> ST s (STUArray s i Int32) # newArray_ :: Ix i => (i, i) -> ST s (STUArray s i Int32) # unsafeNewArray_ :: Ix i => (i, i) -> ST s (STUArray s i Int32) unsafeRead :: Ix i => STUArray s i Int32 -> Int -> ST s Int32 unsafeWrite :: Ix i => STUArray s i Int32 -> Int -> Int32 -> ST s ()
MArray (STUArray s) Int16 (ST s) # |
Instance details Defined in Data.Array.Base Methods getBounds :: Ix i => STUArray s i Int16 -> ST s (i, i) # getNumElements :: Ix i => STUArray s i Int16 -> ST s Int newArray :: Ix i => (i, i) -> Int16 -> ST s (STUArray s i Int16) # newArray_ :: Ix i => (i, i) -> ST s (STUArray s i Int16) # unsafeNewArray_ :: Ix i => (i, i) -> ST s (STUArray s i Int16) unsafeRead :: Ix i => STUArray s i Int16 -> Int -> ST s Int16 unsafeWrite :: Ix i => STUArray s i Int16 -> Int -> Int16 -> ST s ()
MArray (STUArray s) Int8 (ST s) # |
Instance details Defined in Data.Array.Base Methods getBounds :: Ix i => STUArray s i Int8 -> ST s (i, i) # getNumElements :: Ix i => STUArray s i Int8 -> ST s Int newArray :: Ix i => (i, i) -> Int8 -> ST s (STUArray s i Int8) # newArray_ :: Ix i => (i, i) -> ST s (STUArray s i Int8) # unsafeNewArray_ :: Ix i => (i, i) -> ST s (STUArray s i Int8) unsafeRead :: Ix i => STUArray s i Int8 -> Int -> ST s Int8 unsafeWrite :: Ix i => STUArray s i Int8 -> Int -> Int8 -> ST s ()
MArray (STUArray s) Double (ST s) # |
Instance details Defined in Data.Array.Base Methods getBounds :: Ix i => STUArray s i Double -> ST s (i, i) # getNumElements :: Ix i => STUArray s i Double -> ST s Int newArray :: Ix i => (i, i) -> Double -> ST s (STUArray s i Double) # newArray_ :: Ix i => (i, i) -> ST s (STUArray s i Double) # unsafeNewArray_ :: Ix i => (i, i) -> ST s (STUArray s i Double) unsafeRead :: Ix i => STUArray s i Double -> Int -> ST s Double unsafeWrite :: Ix i => STUArray s i Double -> Int -> Double -> ST s ()
MArray (STUArray s) Float (ST s) # |
Instance details Defined in Data.Array.Base Methods getBounds :: Ix i => STUArray s i Float -> ST s (i, i) # getNumElements :: Ix i => STUArray s i Float -> ST s Int newArray :: Ix i => (i, i) -> Float -> ST s (STUArray s i Float) # newArray_ :: Ix i => (i, i) -> ST s (STUArray s i Float) # unsafeNewArray_ :: Ix i => (i, i) -> ST s (STUArray s i Float) unsafeRead :: Ix i => STUArray s i Float -> Int -> ST s Float unsafeWrite :: Ix i => STUArray s i Float -> Int -> Float -> ST s ()
MArray (STUArray s) Word (ST s) # |
Instance details Defined in Data.Array.Base Methods getBounds :: Ix i => STUArray s i Word -> ST s (i, i) # getNumElements :: Ix i => STUArray s i Word -> ST s Int newArray :: Ix i => (i, i) -> Word -> ST s (STUArray s i Word) # newArray_ :: Ix i => (i, i) -> ST s (STUArray s i Word) # unsafeNewArray_ :: Ix i => (i, i) -> ST s (STUArray s i Word) unsafeRead :: Ix i => STUArray s i Word -> Int -> ST s Word unsafeWrite :: Ix i => STUArray s i Word -> Int -> Word -> ST s ()
MArray (STUArray s) Int (ST s) # |
Instance details Defined in Data.Array.Base Methods getBounds :: Ix i => STUArray s i Int -> ST s (i, i) # getNumElements :: Ix i => STUArray s i Int -> ST s Int newArray :: Ix i => (i, i) -> Int -> ST s (STUArray s i Int) # newArray_ :: Ix i => (i, i) -> ST s (STUArray s i Int) # unsafeNewArray_ :: Ix i => (i, i) -> ST s (STUArray s i Int) unsafeRead :: Ix i => STUArray s i Int -> Int -> ST s Int unsafeWrite :: Ix i => STUArray s i Int -> Int -> Int -> ST s ()
MArray (STUArray s) Char (ST s) # |
Instance details Defined in Data.Array.Base Methods getBounds :: Ix i => STUArray s i Char -> ST s (i, i) # getNumElements :: Ix i => STUArray s i Char -> ST s Int newArray :: Ix i => (i, i) -> Char -> ST s (STUArray s i Char) # newArray_ :: Ix i => (i, i) -> ST s (STUArray s i Char) # unsafeNewArray_ :: Ix i => (i, i) -> ST s (STUArray s i Char) unsafeRead :: Ix i => STUArray s i Char -> Int -> ST s Char unsafeWrite :: Ix i => STUArray s i Char -> Int -> Char -> ST s ()
MArray (STUArray s) Bool (ST s) # |
Instance details Defined in Data.Array.Base Methods getBounds :: Ix i => STUArray s i Bool -> ST s (i, i) # getNumElements :: Ix i => STUArray s i Bool -> ST s Int newArray :: Ix i => (i, i) -> Bool -> ST s (STUArray s i Bool) # newArray_ :: Ix i => (i, i) -> ST s (STUArray s i Bool) # unsafeNewArray_ :: Ix i => (i, i) -> ST s (STUArray s i Bool) unsafeRead :: Ix i => STUArray s i Bool -> Int -> ST s Bool unsafeWrite :: Ix i => STUArray s i Bool -> Int -> Bool -> ST s ()
MArray (STUArray s) (StablePtr a) (ST s) # |
Instance details Defined in Data.Array.Base Methods getBounds :: Ix i => STUArray s i (StablePtr a) -> ST s (i, i) # getNumElements :: Ix i => STUArray s i (StablePtr a) -> ST s Int newArray :: Ix i => (i, i) -> StablePtr a -> ST s (STUArray s i (StablePtr a)) # newArray_ :: Ix i => (i, i) -> ST s (STUArray s i (StablePtr a)) # unsafeNewArray_ :: Ix i => (i, i) -> ST s (STUArray s i (StablePtr a)) unsafeRead :: Ix i => STUArray s i (StablePtr a) -> Int -> ST s (StablePtr a) unsafeWrite :: Ix i => STUArray s i (StablePtr a) -> Int -> StablePtr a -> ST s ()
MArray (STUArray s) (FunPtr a) (ST s) # |
Instance details Defined in Data.Array.Base Methods getBounds :: Ix i => STUArray s i (FunPtr a) -> ST s (i, i) # getNumElements :: Ix i => STUArray s i (FunPtr a) -> ST s Int newArray :: Ix i => (i, i) -> FunPtr a -> ST s (STUArray s i (FunPtr a)) # newArray_ :: Ix i => (i, i) -> ST s (STUArray s i (FunPtr a)) # unsafeNewArray_ :: Ix i => (i, i) -> ST s (STUArray s i (FunPtr a)) unsafeRead :: Ix i => STUArray s i (FunPtr a) -> Int -> ST s (FunPtr a) unsafeWrite :: Ix i => STUArray s i (FunPtr a) -> Int -> FunPtr a -> ST s ()
MArray (STUArray s) (Ptr a) (ST s) # |
Instance details Defined in Data.Array.Base Methods getBounds :: Ix i => STUArray s i (Ptr a) -> ST s (i, i) # getNumElements :: Ix i => STUArray s i (Ptr a) -> ST s Int newArray :: Ix i => (i, i) -> Ptr a -> ST s (STUArray s i (Ptr a)) # newArray_ :: Ix i => (i, i) -> ST s (STUArray s i (Ptr a)) # unsafeNewArray_ :: Ix i => (i, i) -> ST s (STUArray s i (Ptr a)) unsafeRead :: Ix i => STUArray s i (Ptr a) -> Int -> ST s (Ptr a) unsafeWrite :: Ix i => STUArray s i (Ptr a) -> Int -> Ptr a -> ST s ()
Eq (STUArray s i e) # |
Instance details Defined in Data.Array.Base Methods (==) :: STUArray s i e -> STUArray s i e -> Bool # (/=) :: STUArray s i e -> STUArray s i e -> Bool #

runSTUArray :: (forall s. ST s (STUArray s i e)) -> UArray i e #

A safe way to create and work with an unboxed mutable array before returning an immutable array for later perusal. This function avoids copying the array before returning it - it uses `unsafeFreeze` internally, but this wrapper is a safe interface to that function.

# Overloaded mutable array interface

module Data.Array.MArray.Safe