One of the pitfall of OCaml that seems completely at odd with the language design has always been the generic comparators: use them on the wrong value type and your program will crash at runtimne, despite the compiler not emitting a single warning. For instance:
$ echo let x = compare (+) (-) > boum.ml $ ocamlc boum.m # No warning here $ ./a.out Fatal error: exception Invalid_argument("compare: functional value") Raised by primitive operation at unknown location (inlined)
I know of only two cases where one get this behavior:
- comparing any type that embodies any function
- comparing external values with no comparison operator defined
In both cases (but esp the first case) it seems to me the compiler should be able to emit a warning.
Am I missing something?