Module

Wasm.Array

Package
purescript-wasm-base
Repository
purs-wasm/purescript-wasm-base

The first-order array primitives the higher-order array combinators are built on. The foreign imports resolve to intrinsics on the wasm backend (Intrinsics.qualifiedIntrinsicWasm.Array.*), so they need no .wat; the accompanying Wasm/Array.js provides them for stock purs / purs-backend-es, so a wasm-base-using project also compiles and runs on the JS backends. On wasm the JS foreigns are ignored.

#length Source

length :: forall a. Array a -> Int

The element count. On wasm: the ArrayLength intrinsic (array.len).

#unsafeIndex Source

unsafeIndex :: forall a. Array a -> Int -> a

The element at index i, unchecked (no bounds test — out of range traps). On wasm: the ArrayIndex intrinsic (array.get; the element is already an eqref, no box).

#unsafeNew Source

unsafeNew :: forall a. Int -> Array a

Allocate a length-n array whose elements are uninitialised (null) until written — reading before unsafeSet traps. On wasm: the ArrayNew intrinsic (array.new).

#unsafeSet Source

unsafeSet :: forall a. Array a -> Int -> a -> Array a

Write v at index i, mutating the array in place, and return that same array, so a builder loop threads it — keeping the write live (not dead-code-eliminated) and ordered by the data dependency, without needing an effect. Unchecked (out of range traps). On wasm: the ArraySet intrinsic (array.set, then yields the array).