Chapter 9 Summary

Short summaries of each section, as well as the overall chapter.

Learning objectives:

  • Explain the list datatype

  • Explain how to pattern match on lists

  • Explain the special syntax that Haskell provides to make working with lists more concise

  • Learn about the representation of lists values as a series of linked data constructors

  • See what this representation means for lists evaluation

  • Do a lot of exercises

9.2 The list datatype

This section explains the components of the list datatype, a little bit about how many values can be constructed by each data constructor, and also alludes to the performance characteristics of the type by comparing it to singly-linked lists.

Paragraph one and the first example show the data declaration of the list type.

Paragraph two clarifies how to read the cons data constructor. (:) is an infix data constructor. The right argument to (:) is a type argument (list-of-a [a]) rather than the nill data constructor (end-of-list []), even though they’re written similarly.

Paragraph three discusses the relationship between the arguments belonging to each data constructor and the number of term-level values that it can construct. The number of values that the list type can construct is a sum of all possible values that each data constructor can construct.

Paragraph four and its accompanying figure explains how to read each part of the data declaration.

Paragraph five explains that cons’ right argument is a self-reference to the list type, so the number of term-level values cons can construct is infinite.

Paragraph six mentions that lists have similar performance to singly-linked lists (which means cons cells may be spread out in different memory locations on the heap) and also that they’re evaluated lazily and can be infinite.

9.8 Spines and non-strict evaluation

9.8.2 Spines are evaluated independently of values