array-0.4.0.1: Mutable and immutable arrays

Portabilitynon-portable (uses Data.Array.Base)
Stabilityexperimental
Maintainerlibraries@haskell.org
Safe HaskellTrustworthy

Data.Array.MArray.Safe

Contents

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. . Safe API only of Data.Array.MArray.

Synopsis

Class of mutable array types

class Monad m => MArray a e m whereSource

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.

Methods

getBounds :: Ix i => a i e -> m (i, i)Source

Returns the bounds of the array

newArray :: Ix i => (i, i) -> e -> m (a i e)Source

Builds a new array, with every element initialised to the supplied value.

newArray_ :: Ix i => (i, i) -> m (a i e)Source

Builds a new array, with every element initialised to an undefined value. In a monadic context in which operations must be deterministic (e.g. the ST monad), the array elements are initialised to a fixed but undefined value, such as zero.

Instances

Monad IO => MArray IOArray e IO 
MArray IOUArray Bool IO 
MArray IOUArray Char IO 
MArray IOUArray Double IO 
MArray IOUArray Float IO 
MArray IOUArray Int IO 
MArray IOUArray Int8 IO 
MArray IOUArray Int16 IO 
MArray IOUArray Int32 IO 
MArray IOUArray Int64 IO 
MArray IOUArray Word IO 
MArray IOUArray Word8 IO 
MArray IOUArray Word16 IO 
MArray IOUArray Word32 IO 
MArray IOUArray Word64 IO 
(Monad IO, Storable e) => MArray StorableArray e IO 
Monad IO => MArray IOUArray (StablePtr a) IO 
Monad IO => MArray IOUArray (Ptr a) IO 
Monad IO => MArray IOUArray (FunPtr a) IO 
Monad (ST s) => MArray (STArray s) e (ST s) 
Monad (ST s) => MArray (STArray s) e (ST s) 
Monad (ST s) => MArray (STUArray s) Word64 (ST s) 
Monad (ST s) => MArray (STUArray s) Word32 (ST s) 
Monad (ST s) => MArray (STUArray s) Word16 (ST s) 
Monad (ST s) => MArray (STUArray s) Word8 (ST s) 
Monad (ST s) => MArray (STUArray s) Int64 (ST s) 
Monad (ST s) => MArray (STUArray s) Int32 (ST s) 
Monad (ST s) => MArray (STUArray s) Int16 (ST s) 
Monad (ST s) => MArray (STUArray s) Int8 (ST s) 
Monad (ST s) => MArray (STUArray s) Double (ST s) 
Monad (ST s) => MArray (STUArray s) Float (ST s) 
Monad (ST s) => MArray (STUArray s) Word (ST s) 
Monad (ST s) => MArray (STUArray s) Int (ST s) 
Monad (ST s) => MArray (STUArray s) Char (ST s) 
Monad (ST s) => MArray (STUArray s) Bool (ST s) 
Monad (ST s) => MArray (STUArray s) (StablePtr a) (ST s) 
Monad (ST s) => MArray (STUArray s) (FunPtr a) (ST s) 
Monad (ST s) => MArray (STUArray s) (Ptr a) (ST s) 

The Ix class and operations

module Data.Ix

Constructing mutable arrays

newListArray :: (MArray a e m, Ix i) => (i, i) -> [e] -> m (a i e)Source

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 eSource

Read an element from a mutable array

writeArray :: (MArray a e m, Ix i) => a i e -> i -> e -> m ()Source

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

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

Constructs a new array derived from the original array by applying a function to each of the indices.

Deconstructing mutable arrays

getElems :: (MArray a e m, Ix i) => a i e -> m [e]Source

Return a list of all the elements of a mutable array

getAssocs :: (MArray a e m, Ix i) => a i e -> m [(i, e)]Source

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

Converts a mutable array (any instance of MArray) to an immutable array (any instance of IArray) by taking a complete copy of it.

thaw :: (Ix i, IArray a e, MArray b e m) => a i e -> m (b i e)Source

Converts an immutable array (any instance of IArray) into a mutable array (any instance of MArray) by taking a complete copy of it.