Haskell Hierarchical Libraries (base package)ContentsIndex
Data.Array.MArray
Portability non-portable
Stability experimental
Maintainer libraries@haskell.org
Contents
Class of mutable array types
Class of array types with bounds
The Ix class and operations
Constructing mutable arrays
Reading and writing mutable arrays
Derived arrays
Deconstructing mutable arrays
Conversions between mutable and immutable arrays
Description
An overloaded interface to mutable arrays. For array types which can be used with this interface, see Data.Array.IO, Data.Array.ST, and Data.Array.Storable.
Synopsis
class (HasBounds a, Monad m) => MArray a e m
class HasBounds a
module Data.Ix
newArray :: (MArray a e m, Ix i) => (i, i) -> e -> m (a i e)
newArray_ :: (MArray a e m, Ix i) => (i, i) -> m (a i e)
newListArray :: (MArray a e m, Ix i) => (i, i) -> [e] -> m (a i e)
readArray :: (MArray a e m, Ix i) => a i e -> i -> m e
writeArray :: (MArray a e m, Ix i) => a i e -> i -> e -> m ()
mapArray :: (MArray a e' m, MArray a e m, Ix i) => (e' -> e) -> a i e' -> m (a i e)
mapIndices :: (MArray a e m, Ix i, Ix j) => (i, i) -> (i -> j) -> a j e -> m (a i e)
bounds :: (HasBounds a, Ix i) => a i e -> (i, i)
indices :: (HasBounds a, Ix i) => a i e -> [i]
getElems :: (MArray a e m, Ix i) => a i e -> m [e]
getAssocs :: (MArray a e m, Ix i) => a i e -> m [(i, e)]
freeze :: (Ix i, MArray a e m, IArray b e) => a i e -> m (b i e)
unsafeFreeze :: (Ix i, MArray a e m, IArray b e) => a i e -> m (b i e)
thaw :: (Ix i, IArray a e, MArray b e m) => a i e -> m (b i e)
unsafeThaw :: (Ix i, IArray a e, MArray b e m) => a i e -> m (b i e)
Class of mutable array types
class (HasBounds a, Monad m) => MArray a e m

Class of mutable array types.

An array type has the form (a i e) where a is the array type constructor (kind * -> * -> *), i is the index type (a member of the class Ix), and e is the element type.

The MArray class is parameterised over both a and e (so that instances specialised to certain element types can be defined, in the same way as for IArray), and also over the type of the monad, m, in which the mutable array will be manipulated.

Instances
MArray (STArray s) e (ST s)
MArray (STUArray s) Bool (ST s)
MArray (STUArray s) Char (ST s)
MArray (STUArray s) Int (ST s)
MArray (STUArray s) Word (ST s)
MArray (STUArray s) (Ptr a) (ST s)
MArray (STUArray s) (FunPtr a) (ST s)
MArray (STUArray s) Float (ST s)
MArray (STUArray s) Double (ST s)
MArray (STUArray s) (StablePtr a) (ST s)
MArray (STUArray s) Int8 (ST s)
MArray (STUArray s) Int16 (ST s)
MArray (STUArray s) Int32 (ST s)
MArray (STUArray s) Int64 (ST s)
MArray (STUArray s) Word8 (ST s)
MArray (STUArray s) Word16 (ST s)
MArray (STUArray s) Word32 (ST s)
MArray (STUArray s) Word64 (ST s)
MArray IOArray e IO
MArray IOUArray Bool IO
MArray IOUArray Char IO
MArray IOUArray Int IO
MArray IOUArray Word IO
MArray IOUArray (Ptr a) IO
MArray IOUArray (FunPtr a) IO
MArray IOUArray Float IO
MArray IOUArray Double IO
MArray IOUArray (StablePtr a) IO
MArray IOUArray Int8 IO
MArray IOUArray Int16 IO
MArray IOUArray Int32 IO
MArray IOUArray Int64 IO
MArray IOUArray Word8 IO
MArray IOUArray Word16 IO
MArray IOUArray Word32 IO
MArray IOUArray Word64 IO
Storable e => MArray StorableArray e IO
Class of array types with bounds
class HasBounds a
Class of array types with bounds
Instances
HasBounds Array
HasBounds UArray
HasBounds (STArray s)
HasBounds (STUArray s)
HasBounds a => HasBounds (IOToDiffArray a)
HasBounds IOArray
HasBounds IOUArray
HasBounds StorableArray
The Ix class and operations
module Data.Ix
Constructing mutable arrays
newArray :: (MArray a e m, Ix i) => (i, i) -> e -> m (a i e)
Builds a new array, with every element initialised to the supplied value.
newArray_ :: (MArray a e m, Ix i) => (i, i) -> m (a i e)
Builds a new array, with every element initialised to undefined.
newListArray :: (MArray a e m, Ix i) => (i, i) -> [e] -> m (a i e)
Constructs a mutable array from a list of initial elements. The list gives the elements of the array in ascending order beginning with the lowest index.
Reading and writing mutable arrays
readArray :: (MArray a e m, Ix i) => a i e -> i -> m e
Read an element from a mutable array
writeArray :: (MArray a e m, Ix i) => a i e -> i -> e -> m ()
Write an element in a mutable array
Derived arrays
mapArray :: (MArray a e' m, MArray a e m, Ix i) => (e' -> e) -> a i e' -> m (a i e)
Constructs a new array derived from the original array by applying a function to each of the elements.
mapIndices :: (MArray a e m, Ix i, Ix j) => (i, i) -> (i -> j) -> a j e -> m (a i e)
Constructs a new array derived from the original array by applying a function to each of the indices.
Deconstructing mutable arrays
bounds :: (HasBounds a, Ix i) => a i e -> (i, i)
Extracts the bounds of an array
indices :: (HasBounds a, Ix i) => a i e -> [i]
Returns a list of all the valid indices in an array.
getElems :: (MArray a e m, Ix i) => a i e -> m [e]
Return a list of all the elements of a mutable array
getAssocs :: (MArray a e m, Ix i) => a i e -> m [(i, e)]
Return a list of all the associations of a mutable array, in index order.
Conversions between mutable and immutable arrays
freeze :: (Ix i, MArray a e m, IArray b e) => a i e -> m (b i e)
Converts a mutable array (any instance of MArray) to an immutable array (any instance of IArray) by taking a complete copy of it.
unsafeFreeze :: (Ix i, MArray a e m, IArray b e) => a i e -> m (b i e)

Converts an mutable array into an immutable array. The implementation may either simply cast the array from one type to the other without copying the array, or it may take a full copy of the array.

Note that because the array is possibly not copied, any subsequent modifications made to the mutable version of the array may be shared with the immutable version. It is safe to use, therefore, if the mutable version is never modified after the freeze operation.

The non-copying implementation is supported between certain pairs of array types only; one constraint is that the array types must have identical representations. In GHC, The following pairs of array types have a non-copying O(1) implementation of unsafeFreeze. Because the optimised versions are enabled by specialisations, you will need to compile with optimisation (-O) to get them.

thaw :: (Ix i, IArray a e, MArray b e m) => a i e -> m (b i e)
Converts an immutable array (any instance of IArray) into a mutable array (any instance of MArray) by taking a complete copy of it.
unsafeThaw :: (Ix i, IArray a e, MArray b e m) => a i e -> m (b i e)

Converts an immutable array into a mutable array. The implementation may either simply cast the array from one type to the other without copying the array, or it may take a full copy of the array.

Note that because the array is possibly not copied, any subsequent modifications made to the mutable version of the array may be shared with the immutable version. It is safe to use, therefore, if the immutable version is never referenced again.

The non-copying implementation is supported between certain pairs of array types only; one constraint is that the array types must have identical representations. In GHC, The following pairs of array types have a non-copying O(1) implementation of unsafeFreeze. Because the optimised versions are enabled by specialisations, you will need to compile with optimisation (-O) to get them.

Produced by Haddock version 0.6