I just learned that OCAML have to have a .
postfix for doing float arithmetic. An example would be 3. +. 4.
which equals 7.
(float). However, F# handles float and integer arithmetic in the same way, so both 3 + 4
(int) and 3. + 4.
(float) works.
F# have +
naturally assigned to int so let add a b = a + b
is of type int -> int -> int
. And indeed (+)
gives me val it : (int -> int -> int) = <fun:it@6-1>
.
That leads to the following sequence which I think quite counter-intuitive:
> 3. + 4.;;
val it : float = 7.0
> (+);;
val it : (int -> int -> int) = <fun:it@8-2>
So my question is: Is the "overloading" done by a special mechanism/case in the compiler or is this a language-wide thing so I potentially can define a function called add
(or anything else) which have a one definition for integers and one for floats (or any other type.)