|
Data.Primitive.Array | Portability | non-portable | Maintainer | Roman Leshchinskiy <rl@cse.unsw.edu.au> |
|
|
|
Description |
Primitive boxed arrays
|
|
Synopsis |
|
|
|
Documentation |
|
|
Boxed arrays
| Constructors | | Instances | |
|
|
|
Mutable boxed arrays associated with a primitive state token.
| Constructors | | Instances | |
|
|
|
Create a new mutable array of the specified size and initialise all
elements with the given value.
|
|
|
Read a value from the array at the given index.
|
|
|
Write a value to the array at the given index.
|
|
|
Read a value from the immutable array at the given index.
|
|
|
Monadically read a value from the immutable array at the given index.
This allows us to be strict in the array while remaining lazy in the read
element which is very useful for collective operations. Suppose we want to
copy an array. We could do something like this:
copy marr arr ... = do ...
writeArray marr i (indexArray arr i) ...
...
But since primitive arrays are lazy, the calls to indexArray will not be
evaluated. Rather, marr will be filled with thunks each of which would
retain a reference to arr. This is definitely not what we want!
With indexArrayM, we can instead write
copy marr arr ... = do ...
x <- indexArrayM arr i
writeArray marr i x
...
Now, indexing is executed immediately although the returned element is
still not evaluated.
|
|
|
Convert a mutable array to an immutable one without copying. The
array should not be modified after the conversion.
|
|
|
Convert an immutable array to an mutable one without copying. The
immutable array should not be used after the conversion.
|
|
|
Check whether the two arrays refer to the same memory block.
|
|
Produced by Haddock version 2.6.1 |