I am wondering why < operator supports int, string, bool, or float, whereas + only support int.
Could OCaml recognize the underlying arithmetic to use ? What makes comparison operator different from arithmetic ones ? Is it the same for other FP language ?
Comparison Operators are used to perform comparisons. Concatenation Operators are used to combine strings. Logical Operators are used to perform logical operations and include AND, OR, or NOT. Boolean Operators include AND, OR, XOR, or NOT and can have one of two values, true or false.
OCaml distinguishes between structural equality and physical equality (essentially equality of the address of an object). = is structural equality and == is physical equality.
There are two equality operators in OCaml, = and == , with corresponding inequality operators <> and !=
The |> operator represents reverse function application.
There is not, at the moment, a notion of "a bit polymorphic" in OCaml (the technical name is "ad-hoc polymorphism"). You can't say "I accept integers and floats but not the rest".
You can say, however "I accept everything", just like the comparison operator (the technical name is "parametric polymorphism"). Do note however than they are lying a bit about that: you can't compare functions, even if the type system can't catch it.
See this answer for details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With