Array.Hamt

Fast immutable arrays. The elements in an array must have the same type.

Arrays

type Array a
= {-
* length : Int = The length of the array.
* startShift : Int = How many bits to shift the index to get the
slot for the first level of the tree.
* tree : Tree a = The actual tree.
* tail : JsArray a = The tail of the array. Inserted into tree when
number of elements is equal to the branching factor. This is an
optimization. It makes operations at the end (push, pop, read, write)
fast.
-}
Array Int Int (Tree a) (JsArray a)

Representation of fast immutable arrays. You can create arrays of integers
(Array Int) or strings (Array String) or any other type of value you can
dream up.

Creation

empty : Array a

Return an empty array.

length empty == 0

initialize : Int -> (Int -> a) -> Array a

Initialize an array. initialize n f creates an array of length n with
the element at index i initialized to the result of (f i).

Manipulate

Set the element at a particular index. Returns an updated array.
If the index is out of range, the array is unaltered.

set 1 7 (fromList [1,2,3]) == fromList [1,7,3]

push : a -> Array a -> Array a

Push an element onto the end of an array.

push 3 (fromList [1,2]) == fromList [1,2,3]

append : Array a -> Array a -> Array a

Append two arrays to a new one.

append (repeat 2 42) (repeat 3 81) == fromList [42,42,81,81,81]

slice : Int -> Int -> Array a -> Array a

Get a sub-section of an array: (slice start end array). The start is a
zero-based index where we will start our slice. The end is a zero-based index
that indicates the end of the slice. The slice extracts up to but not including
end.