tur/list

stdlib/list.tur
defstruct

Cons

(defstruct Cons [value :int next :int])
defn

nil-value

(nil-value)

return the empty list sentinel (NULL / 0).

Since: Phase B1

defn

list-nil?

(list-nil? [lst] :bool)

check whether a list is empty.

lstthe list to test

Since: Phase B1

defn

cons

(cons [value next] :int)

prepend a value to a list, returning a new Cons cell.

valuethe element to prepend
nextthe existing list (or nil-value for a one-element list)

Since: Phase B1

defn

tail

(tail [lst] :int)

return the rest of the list after the first element.

lsta non-nil list

Since: Phase B1

defn

list-free

(list-free [lst])

free all Cons cells in a list (shallow -- does not free contained values).

lstthe list to free (may be nil-value)

Since: Phase B1

defn

list-length

(list-length [lst] :int)

return the number of elements in a list.

lstthe list to measure

Since: Phase B1

definstance

Clone[Cons]

(definstance Clone [Cons])

shallow Clone for a single Cons cell.

definstance

Functor[list]

(definstance Functor [list])

Functor: fmap over every element.

definstance

Foldable[list]

(definstance Foldable [list])

Foldable: foldl and foldr over all elements.

definstance

Applicative[list]

(definstance Applicative [list])

Applicative: pure and ap.

definstance

Monad[list]

(definstance Monad [list])

Monad: bind (concat-map).

defn

list-eq?

(list-eq? [l1 l2 cmp-fn] :bool)

compare two lists element-wise using a caller-supplied comparator.

l1first list
l2second list
cmp-fncomparator of type fn [a :int b :int] :bool

Since: Phase E1

definstance

Eq[list]

(definstance Eq [list])

Eq: structural equality via list-eq?.

Internal definitions
__functor_list_fmap-- SINCE: Phase HKT §6 — Stdlib HKT migration
__foldable_list_foldl-- foldl implementation for the list Foldable instance.
__foldable_list_foldr-- foldr implementation for the list Foldable instance.
__applicative_list_pure-- pure implementation for the list Applicative instance.
__applicative_list_ap-- ap implementation for the list Applicative instance.
__monad_list_bind-- bind implementation for the list Monad instance.