Chapter ordering
Chapter 4 leads with the factorial function example:
fact :: Int -> Int
fact 0 = 1
fact n = n * fact (n - 1)
This is the answer to 5.5 exercise 1, the chapter in which pattern matching is introduced.
fact is the canonical recursion example and should remain where it is, but I think pattern matching could be introduced before recursion.
This got me thinking about chapter ordering in general. I think the following ordering/grouping could be easier to follow.
- Simple Types, Arrays, and Records
- Functions
- Pattern Matching
- Recursion and Higher Order Functions
- Types, Kinds and Type Constructors
- Type Classes
Basic value types and type constructor literals should be introduced as early as possible:
String
Number
Int
Boolean
Array
Record
The examples/exercises in Chapter 3 appear to require a knowledge of type, but covering this section without user-defined types could motivate learning about/using them later.
Pattern matching extends the discussion of defining functions.
My biggest source of confusion through chapter 5 has been the difference between data, type and newtype. I think they should build upon each other:
typeis for creating type aliases purely for the developer's conveniencedatais for creating user-defined types (type constructors)newtypeis for creating nominal type aliases
Of course this is just my opinion. Others may disagree.
The examples/exercises in Chapter 3 appear to require a knowledge of type, but covering this section without user-defined types could motivate learning about/using them later.
On second thought, just using type in chapter 3 without explanation is fine. But emphasizing that it is just an alias in a later "Types" chapter would be helpful.
Currently in chapter 3 the term "type synonym" is used a couple of times, but no explanation is given as to what this means to the compiler. In chapter 5 it's just mentioned in passing. There's no contrast w/ data or newtype.