Definition 251.1(Lists).
Homogeneous collection of elements. Indexing starts at 0.
Infix list operators
- Lists are concatenated by the
++operator. Haskell has to iterate through the entire list on the left. - Elements can be prepended to lists in O(1) time by using the
:operator'A':" SMALL CAT" - Indices are accessed using the
!!operator[9.4,33.2,96.2,11.2,23.25] !! 1 - Relational operators compare lists in lexicographical order. Lists of different sizes can be compared.
Prefix list operations
lengthnullchecks if a list is empty.reversetaketakes a number and a list, and extracts said number of elements from the beginning of the list.dropopposite oftakemaximumworks on all lists which can be orderedminimumdittosumelemtakes a thing and a list of things; returns true if thing is in list.cycletakes a list and cycles it into an infinite list.repeattakes an element and produces an infinite list of just that element.
Do not use these on empty lists!
headreturns the first elementtailpops the first element and returns the remnant (‘tail’)lastreturns the last elementinitpops the last element and returns the remnant