The title says it.
In OCaml, you can do 1 + 1 but not 1.0 + 1.0
I kinda get this, '+' is a function that takes two int argument.
But why do we have '>' that works for float and int?
Is this inconsistency?
The title says it.
In OCaml, you can do 1 + 1 but not 1.0 + 1.0
I kinda get this, '+' is a function that takes two int argument.
But why do we have '>' that works for float and int?
Is this inconsistency?
Well, note that '>' works for two values of any one type. It's not just for numbers.
But yes, the polymorphic comparison operators are a kind of special case in OCaml. Theoretically it shouldn't be possible to define such functions, as there's no a priori way to "look inside" values with arbitrary types. However the functions exist anyway because they're extremely useful.
They are also somewhat dangerous, and many OCaml experts advise being very careful with them.
There is some discussion of the limitations here: Does compare work for all types?