Array package:primitive

Primitive arrays of boxed values.
Boxed arrays.
Create an array from a list.
Create an array from a list of a known length. If the length of the list does not match the given length, this throws an exception.
Mutable boxed arrays associated with a primitive state token.
Return a newly allocated Array with the specified subrange of the provided Array. Note: The provided array should contain the full subrange specified by the two Ints, but this is not checked.
Return a newly allocated MutableArray. with the specified subrange of the provided MutableArray. The provided MutableArray should contain the full subrange specified by the two Ints, but this is not checked. Note: The provided array should contain the full subrange specified by the two Ints, but this is not checked.
Copy a slice of an immutable array to a mutable array. Note: this function does not do bounds or overlap checking.
Copy a slice of a mutable array to another array. The two arrays may overlap. Note: this function does not do bounds or overlap checking.
Create an array of the given size with a default value, apply the monadic function and freeze the result. If the size is 0, return emptyArray (rather than a new copy thereof).
createArray 0 _ _ = emptyArray
createArray n x f = runArray $ do
mary <- newArray n x
f mary
pure mary
The empty Array.
Create an immutable copy of a slice of an array. This operation makes a copy of the specified section, so it is safe to continue using the mutable array afterward. Note: The provided array should contain the full subrange specified by the two Ints, but this is not checked.
Read a value from the immutable array at the given index. Note: this function does not do bounds checking.
Read a value from the immutable array at the given index, returning the result in an unboxed unary tuple. This is currently used to implement folds. Note: this function does not do bounds checking.
Read a value from the immutable array at the given index using an applicative. 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 the 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. Note: this function does not do bounds checking.
Strict map over the elements of the array.
Create a new mutable array of the specified size and initialise all elements with the given value. Note: this function does not check if the input is non-negative.
Read a value from the array at the given index. Note: this function does not do bounds checking.
Execute the monadic action and freeze the resulting array.
runArray m = runST $ m >>= unsafeFreezeArray
Check whether the two arrays refer to the same memory block.
The number of elements in an immutable array.