I have these two functions:
let print_length = function
| [] -> Printf.printf "The list is empty"
| xs -> Printf.printf "The list has %d elements" (List.length xs)
let print_length = function
| [] -> Printf.printf "The list is empty"
| (_ :: _) as xs -> Printf.printf "The list has %d elements" (List.length xs)
In practice they behave identically, and in theory they should be identical as long as the cases are matched in sequential order. But is this guaranteed in OCaml? What if the some newer version of the compiler starts optimizing match statements by rearranging the order? In that case, only the second version would produce the correct result. Should I be worrying about this?