B.6 Lists
The following are the some important points about lists in ML.
Unlike in Scheme, lists in ML are homogeneous, meaning all elements of the list must be of the same type. For instance, the list [1,2,3] in ML is homogeneous, while the list (1 "apple") in Scheme is heterogeneous.
In a type-safe language like ML the values in a tuple (Section B.7) generally have different types, but the number of elements in the tuple must be fixed. Conversely, the values of a list must all have the same type, but the number of elements in the list is not fixed.
The semantics of the lexemes nil and [] are the empty list.
The cons operator, which accepts an element (the head) and a list (the tail), is :: (e.g., 1::2::[3]) and associates right-to-left.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access