Practical OCaml: minimum review

I have been reading Practical OCaml. I didn’t buy the book; I recommend that you don’t buy it too. I was given a copy and asked if I could say something good about it, so here goes: “it could be worse”.

There are so many other negative reviews of this book I don’t want to just repeat what has already been said. Instead I’m going to criticise some parts of it in more detail in the hope that it may help. I’m going to choose targets on a whim, with not much rhyme or reason; that should mirror the structure of the book quite well.

So, to start small, my first complaint is against page 172. Smith (the book’s author) writes:

let min x y = match x with
    n when x < y -> x
  | _ -> y;;

Huh?!

That can’t possibly be a sane way to define a function that returns the smaller of two arguments. In addition to the needless complexity we have the unused named value n. What was wrong with:

let min x y = if x < y then x else y;;

That should be clear enough. But I now have another question: why even bother? The min function is built-in to OCaml; it is part of the Pervasives module that provides “<” and the other comparison operators.