Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Suggestion for overloaded operators
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Alain Frisch <frisch@c...>
Subject: Re: [Caml-list] Suggestion for overloaded operators
On Sun, 10 Feb 2002, Warp wrote:

> Helo.
> One of missing thing in Ocaml is the possibility to overload the operators
> such as + - / * = (by overloading, i mean : defining such operators for
> other types than -int- )....
> Here's a syntactic proposal to enable this feature :

You say nothing about the typing of static overloading (interaction with
polymorphism and type inference), and this is the crux of the matter.

What type would you give to:
fun a b -> a :+ b
?

This expression has many possible types, and no best one.

Even when the context could allow to statically resolve the overloading,
this may be beyond the current type inference algorithm. For instance:

fun a b -> let r = a :+ b in a + b + r

The end of the expression allows to deduce that a and b are int, but
when :+ is typed, this information is not yet available.

A simple minded solution is to require that enough type information
is available to resolve the overloading at the point where the algorithm
encounters it. This is very similar to the patch I posted to this list
about overloading of record labels, and the same arguments against it
apply as well.


Maybe you should have a look at G'Caml:
http://pauillac.inria.fr/~furuse/generics/


-- Alain

-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr