Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

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: 2005-04-09 (02:58)
From: Jon Harrop <jon@f...>
Subject: Re: [Caml-list] ambitious proposal: polymorphic arithmetics
On Wednesday 06 April 2005 16:15, 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.

I'm just curious, but what would you have expected the result of:

# (1, 2, 3) * (2, 3, 4);;

to be? i.e. an inner product, element-wise multiplication or an outer product?

> P.S. I believe I'm not proposing anything as serious as Haskell type
> classes.

Oh, this isn't serious? ;-)

> If so, I can perhaps restate my question as: why is the line drawn between =
> and + now?

I would say that polymorphic comparisons are useful in many more circumstances 
than polymorphic arithmetics would be, so their inclusion is justified.

Dr Jon D Harrop, Flying Frog Consultancy Ltd.
Objective CAML for Scientists