|
Data.Array.MArray | Portability | non-portable (uses Data.Array.Base) | Stability | experimental | Maintainer | libraries@haskell.org |
|
|
|
|
|
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 Monad m => MArray a e m where | | | 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) | | getBounds :: (MArray a e m, Ix i) => a i e -> m (i, 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 Monad m => MArray a e m where |
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) | | newArray :: Ix i => (i, i) -> e -> m (a i e) | | newArray_ :: Ix i => (i, i) -> m (a i e) |
| | Instances | |
|
|
The Ix class and operations
|
|
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 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.
|
|
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
|
|
getBounds :: (MArray a e m, Ix i) => a i e -> m (i, i) |
Returns the bounds of the 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) |
|
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) |
|
Produced by Haddock version 2.3.0 |