Std\IntArray
Contiguous unboxed array of Int values. No per-element reference counting —
the array itself is a single RC-managed allocation. O(1) random access,
cache-friendly iteration, SIMD auto-vectorizable by LLVM.
Implements the Array trait — length and get work via trait dispatch
without explicit imports. The Prelude’s polymorphic foldl also works on
IntArray via runtime type detection.
import fromSeq from Std\IntArray inlet arr = fromSeq [1, 2, 3, 4, 5] inlength arr -- 5 (Array trait)get arr 2 -- 3 (Array trait)foldl (\a b -> a + b) 0 arr -- 15 (polymorphic Prelude foldl)Functions
Section titled “Functions”alloc : Int -> IntArrayAllocate an uninitialized IntArray with the given number of elements.
fill : Int -> Int -> IntArrayCreate an IntArray of n elements, all set to the given value.
import fill from Std\IntArray infill 1000 0 -- 1000 zeroslength
Section titled “length”length : IntArray -> IntO(1) element count.
get : IntArray -> Int -> IntO(1) indexed access. No bounds checking.
import fromSeq, get from Std\IntArray inget (fromSeq [10, 20, 30]) 1 -- 20set : IntArray -> Int -> Int -> IntArrayPersistent set — returns a new array with the element at the given index replaced. O(n) copy.
head : IntArray -> IntFirst element. O(1).
tail : IntArray -> IntArrayAll elements except the first. Returns a new array. O(n) copy.
cons : Int -> IntArray -> IntArrayPrepend an element. Returns a new array. O(n) copy.
join : IntArray -> IntArray -> IntArrayConcatenate two arrays. O(n+m).
slice : IntArray -> Int -> Int -> IntArrayExtract a sub-array starting at start with length elements.
import fromSeq, slice, foldl from Std\IntArray infoldl (\acc x -> acc + x) 0 (slice (fromSeq [10, 20, 30, 40, 50]) 1 3)-- 90 (20 + 30 + 40)map : (Int -> Int) -> IntArray -> IntArrayApply a function to each element, returning a new array. Single-pass, SIMD-eligible for simple operations.
import fromSeq, map, foldl from Std\IntArray infoldl (\acc x -> acc + x) 0 (map (\x -> x * x) (fromSeq [1, 2, 3, 4, 5]))-- 55foldl : (Int -> Int -> Int) -> Int -> IntArray -> IntLeft fold over all elements. Single-pass, cache-friendly.
import fill, foldl from Std\IntArray infoldl (\acc x -> acc + x) 0 (fill 100 1) -- 100filter
Section titled “filter”filter : (Int -> Bool) -> IntArray -> IntArrayKeep elements satisfying the predicate. Two-pass (count + fill).
import fromSeq, filter, foldl from Std\IntArray infoldl (\acc x -> acc + x) 0 (filter (\x -> x % 2 == 0) (fromSeq [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]))-- 30fromSeq
Section titled “fromSeq”fromSeq : [Int] -> IntArrayConvert a sequence to an IntArray. O(n) copy from boxed to unboxed.
toSeq : IntArray -> [Int]Convert an IntArray to a sequence. O(n) copy from unboxed to boxed.