Index-function representation of a list (source code)

= Index-function representation of a list
{title2=$f:\mathbb Z\to\operatorname{Maybe}(A)$}

Represent a finite <list> by a <function> from indices to <optional values>. There must be a length $m$ for which exactly the indices $0\leq i<m$ are present; later indices are absent, so the representation has no holes. Prepending and removing a head shift indices, taking restricts the present domain, and dropping translates it. Functional composition can accumulate query costs, so <array>-like constant-time access does not follow from the representation type.