Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Data.FlatArray

Flat, unboxed-element arrays: one typed surface over the raw-word buffers.

A FlatArray(a) stores its elements as raw 8-byte words in a single contiguous buffer (FloatBuf for Float, IntBuf for I64), so the storage carries no per-element heap cells; only reading an element boxes the scalar it returns. The element types are exactly the fixed-width lanes whose bit pattern fills one word, chosen by the FlatElem instance in scope, so an unsupported element type is a missing-instance error at compile time rather than a runtime representation fault.

The buffers underneath follow the array’s rc==1 in-place / shared-copy discipline, so a uniquely owned flat array updates in place and a shared one copies on write: value semantics, identical on both backends.

Types

FlatArray

type FlatArray(a) = FloatArr(FloatBuf) | IntArr(IntBuf)

A dense array of unboxed one-word elements. The payload variant is chosen by the element’s FlatElem instance; the phantom parameter keeps the two payloads from ever mixing at the type level.

Type Classes

FlatElem

class FlatElem(a)
  fa_new : (Int, a) -> FlatArray(a)
  fa_get : (FlatArray(a), Int) -> a ! {Fail}
  fa_set : (FlatArray(a), Int, a) -> FlatArray(a) ! {Fail}

The element contract: how a one-word scalar enters and leaves the flat storage. Instances exist for Float and I64.

Instances

flatFloat

instance flatFloat : FlatElem(Float)

flatI64

instance flatI64 : FlatElem(I64)

Functions and Values

fa_len

fa_len : forall a. (Data.FlatArray.FlatArray(a)) -> Int

The element count, independent of the element type.