Practical OCaml: not again

I was about to comment on the "Larger Example" in chapter 18, starting on page 243; but first I have to get rid of the trimin method it contains:

    method private trimin x y z = match x,y,z with
        m,n,o when (m > n) -> if (n < o) then n else o
      | m,n,o when (m < n) -> if (m < o) then m else o
      | m,n,o -> if (n < o) then n else o

Let me now repeat exactly what I said in my previous post: Huh?! This method will return the smallest of its three arguments, although its ugliness made me doubt that for a while. But even if it were improved, it shouldn't even be part of this class at all. So I removed that method and replaced it with a simple function:

let trimin x y z = min x (min y z);;

That done, I was then able to continue with the "larger example".

Leave a Reply

Your email address will not be published.