Skip to content

Lists

List<A> is a homogeneous linked list. [head | tail] conses; [] is the empty list. Recursive functions are ordinary functions: all signatures in a module are collected before bodies are checked.

module lists
pub fn prepend(head: Integer, tail: List<Integer>) -> List<Integer> {
[head | tail]
}
pub fn sum(items: List<Integer>) -> Integer {
match items {
[] -> 0
[head | tail] -> head + sum(tail)
}
}