Version française
Home     About     Download     Resources     Contact us    
Browse thread
ambitious proposal: polymorphic arithmetics
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: William Lovas <wlovas@s...>
Subject: Re: [Caml-list] ambitious proposal: polymorphic arithmetics
Hi Eijiro,

On Wed, Apr 06, 2005 at 11:15:05AM -0400, Eijiro Sumii wrote:
> So here it goes: why don't we have polymorphic +, -, etc. while we
> have polymorphic =, <, etc.?  Many novices and (at least) some experts
> feel that +., -., etc. are not quite nice.  Why not define +, -,
> etc. for as many types as possible such as integers, floating-point
> numbers, and tuples?  I think they can be implemented almost in the
> same efficient way as =.  They can also raise an exception if applied
> to unsupported values such as functions, just as = does.

Many experts (and perhaps some novices *shrug*) think that polymorphic
equality is a bad idea... so maybe it's best to just leave "well enough"
alone :)

More seriously, one might argue -- only slightly hand-wavily -- that with
=, <, etc., types whose values *cannot* be used as inputs are the exception
rather than the rule, whereas the reverse is the case for +, -, etc.  For
example, it may be perfectly clear (or at least possible to specify) how to
implement comparisons on data types, records, and tuples.  What should the
arithmetic operators mean on such things?  (This argument breaks down in
the face of code which relies on abstract types to enforce modularity -- in
such cases, incomparability can become "the rule" rather than the
exception, putting =, <, etc. on the same footing as +, -, etc.)

These are just my thoughts, though, and i'm still something of a nameless
student :)

cheers,
William