Open dmitriid opened 7 years ago
And I don't think the concept of "lifting over" is explained anywhere in the book
Found it, Chapter 6.4, section "Functor, and Type Class Laws". So basically the first time map
is presented, it uses a definition from Chapter 6.4 for a function explained in Chapter 4.5 :)
To expand and be more constructive. The introduction in Chapter 3.15 can be replaced wholesale with the introduction from 4.5. That is...
Before:
Fortunately, the Prelude module provides a way to do this. The
map
operator can be used to lift a function over an appropriate type constructor like Maybe (we’ll see more on this function, and others like it, later in the book, when we talk about functors)
After:
Fortunately, the Prelude module provides a way to do this. We can use the
map
function. It is used to transform the elements of an array by applying a function to each element in turn. Therefore, it changes the contents of the array, but preserves its shape (i.e. its length).example
When we cover type classes later in the book we will see that the map function is an example of a more general pattern of shape-preserving functions which transform a class of type constructors called functors.
The book assumes the following:
However, this is how
map
is introduced for the first time in the book (Chapter 3.15):map
itself isn't explained in some detail until Chapter 4.5 (and never mentions "lifting over a type constructor"). And I don't think the concept of "lifting over" is explained anywhere in the book (though I didn't do an exhaustive search :) ). However, even the word "lift" first appears in this paragraph.I believe this is the single most confusing paragraph in the introduction. I've been using
map
daily for the past 7 years or so in Javascript and Erlang, and I have no idea what this paragraph talks about :) (and it essentially stops me from proceeding with the book).