Linked lists: ordered lists, in which each element has a reference to the next element.
Most operations on linked lists take time proportional to the length of the list, because each element must be traversed to find the next element.
List α
is isomorphic to Array α
, but they are useful for different things:
-
List α
is easier for reasoning, andArray α
is modeled as a wrapper aroundList α
. -
List α
works well as a persistent data structure, when many copies of the tail are shared. When the value is not shared,Array α
will have better performance because it can do destructive updates.
Constructors
nil.{u} {α : Type u} : List α
The empty list, usually written []
.
Conventions for notations in identifiers:
-
The recommended spelling of
[]
in identifiers isnil
.