Hi,
I found a missing "does not change" sentence fragment in the third section on Lists and Patterns
"Each
::
essentially adds a new block to the proceding
picture. Such a block contains two things: a reference to the data in that list element, and a
reference to the remainder of the list. This is why ::
can
extend a list without modifying it; extension allocates a new list element but {here} change any of
the existing ones, as you can see: "
The example code using pattern matching appears to be a "let rec" short-circuit which I believe deserves a comment in the book. It appears to be puzzling, we are binding a "zero" to the head of the list in order to drop it? I think it is a fine example of OCaml that should be encouraged, not just an isolated case.
let rec drop_zero ls = match ls with
| [] -> []
| 0 :: tl -> drop_zero tl
| hd :: tl -> hd :: drop_zero tl
;;
With kind regards,
Jean