Why can OCaml generate efficient machine code for pattern matching and not for if-else tests?
I was reading Real World OCaml and I came across this section where they co
Of course, it is possible to optimise the if-else test the same way. For example, you could write a new optimiser that works in 2 stages: first transform all if-else tests to pattern matching where possible (still in OCaml) and then run the existing compiler.
Therefore, the answer must be that optimising if-else tests the same way isn't high on the priority list of the compiler developers.
As a future release of the compiler may bring an even better optimisation for the if-else test, I would only change time-critical code now.