purescript-book icon indicating copy to clipboard operation
purescript-book copied to clipboard

Chapter ordering

Open gabejohnson opened this issue 8 years ago • 1 comments

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.

  1. Simple Types, Arrays, and Records
  2. Functions
  3. Pattern Matching
  4. Recursion and Higher Order Functions
  5. Types, Kinds and Type Constructors
  6. 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:

  • type is for creating type aliases purely for the developer's convenience
  • data is for creating user-defined types (type constructors)
  • newtype is for creating nominal type aliases

Of course this is just my opinion. Others may disagree.

gabejohnson avatar Jul 19 '17 04:07 gabejohnson

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.

gabejohnson avatar Jul 19 '17 20:07 gabejohnson