Getting started

Alex Martelli aleax at aleax.it
Tue Sep 24 11:19:31 EDT 2002


Tibor Simko wrote:

> Hello
> 
> On Mon, 23 Sep 2002, Alex Martelli wrote:
>> as far as I know, the CAML dialect of ML (also in the O'Caml
>> extension, last I looked) is one of the very few programming
>> languages that doesn't have a polymorphic + operator -- you have to
>> use + for integers only, +. for floating-point.
> 
> There is a good reason why OCaml does not overload the + operator:

There is a reason -- whether it's a GOOD one is more debatable:-)

> type inferring.  In OCaml you do not need to declare variables
> explicitly in the program because OCaml infers types for you.
> However, this does not match well with operator overloading, since the
> compiler would not understand whether "a + b" stands for float or
> integer.  Unlike SML, OCaml decided to avoid this kind of type
> inferring problem by not overloading the + operator.

Compare this "solution" to Haskell's typeclasses to see why I
love Haskell so:-).  While SML doesn't seem to suffer unduly
from "overloading" (as you say) `+` , Haskell generalizes this
to a kind of generic-programming ability -- no overloading,
just the right amount of generality.  And without any damage
at all to strong compile-time type safety, nor to type
inferencing (or inferring), of course.


Alex




More information about the Python-list mailing list