Modulelinear-base-0.4.0Haskell2010
Data.Array.Mutable.Linear
This module provides a pure linear interface for arrays with in-place mutation.
To use these mutable arrays, create a linear computation of type
Array a %1-> Ur b and feed it to alloc or fromList.
A Tiny Example
:set -XLinearTypes:set -XNoImplicitPreludeimport Prelude.Linearimport qualified Data.Array.Mutable.Linear as Array:{ isFirstZero :: Array.Array Int %1-> Ur Bool isFirstZero arr = Array.get 0 arr & \(Ur val, arr') -> arr' `lseq` Ur (val == 0):}
unur $ Array.fromList [0..10] isFirstZeroTrueunur $ Array.fromList [1,2,3] isFirstZeroFalse
- 1 type
- 17 values
- Packagelinear-base-0.4.0
- Exports18
- LanguageHaskell2010
- LicenceMIT
- SourceLinear.hs
Mutable Linear Arrays
1 declarationPerforming Computations with Arrays
3 declarationsAllocate a constant array given a size and an initial value The size must be non-negative, otherwise this errors.
Allocate a constant array given a size and an initial value, using another array as a uniqueness proof.
Allocate an array from a list
Modifications
4 declarationsSets the value of an index. The index should be less than the arrays size, otherwise this errors.
Same as set, but does not do bounds-checking. The behaviour is undefined if an out-of-bounds index is provided.
Resize an array. That is, given an array, a target size, and a seed value; resize the array to the given size using the seed value to fill in the new cells when necessary and copying over all the unchanged cells.
Target size should be non-negative.
let b = resize n x a,
then size b = n,
and b[i] = a[i] for i < size a,
and b[i] = x for size a <= i < n.
Accessors
6 declarationsGet the value of an index. The index should be less than the arrays size, otherwise this errors.
Same as get, but does not do bounds-checking. The behaviour is undefined if an out-of-bounds index is provided.
Copy a slice of the array, starting from given offset and copying given number of elements. Returns the pair (oldArray, slice).
Start offset + target size should be within the input array, and both should be non-negative.
let b = slice i n a,
then size b = n,
and b[j] = a[i+j] for 0 <= j < n
Return the array elements as a lazy list.