Version française
Home     About     Download     Resources     Contact us    
Browse thread
status of some big "important" features?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Christophe Raffalli <Christophe.Raffalli@u...>
Subject: A proposal for overloading ...

What follows is a proposal to add overloading to ocaml with the
following properties:

- compatibility of existing code
- simple to implement and understand (it is my opinion)
- not limited to arythmetic operation

The implementation is in two steps:

When parsing an identifier search the list of all value in the
environment having the same name. So at parsing time, the value of an
identifier is a list of Ocaml term. 

At type checking, when type-checking the type of an identifier two cases
occur:
1) there is only one possible value in the list whose type unify with
the required type: in this case we known the real value of the
identifier. (note: in ML type checking implementation, each value in the
environment as a type assigned so we just need to try to unify the
required type with all possible type)
2) there are more than one value whose type unify with the required
type:
in this case we delay the typing-checking of that identifier

* At the end we have a set of identifier whose type checking have been
delayed. It is possible that some identifiers know have only one
possible value (because we got extra typing information). We enter a
loop  until all identifiers have an ambiguous value or all identifier
have been type checked.

Then, if there is still some identifiers with ambiguous value, we choose
one (the first by position in the source code ?), and assign it the
first possible value in the list (this choice insure compatibility with
existing code). This may add extra typing information, so we go back to
step *. It would be good to issue a warning in this case because it may
help detect bugs in the following situation:

let i = ... in
...
let i = ... in
...
i 
...

where both i have the same type and the reference to i reffers to the
first one in the mind of the programmer that did not see the second one.

What do the implementors and users of Ocaml think of this ?
Is it compatible with the complex feature in Ocaml typing  (like
functor, object, type-checking of let rec ..) ?
 
-- 
Christophe Raffalli
Université de Savoie
Batiment Le Chablais, bureau 21
73376 Le Bourget-du-Lac Cedex

tél: (33) 4 79 75 81 03
fax: (33) 4 79 75 87 42
mail: Christophe.Raffalli@univ-savoie.fr
www: http://www.lama.univ-savoie.fr/~RAFFALLI