From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id WAA07909 for caml-red; Sat, 30 Dec 2000 22:37:17 +0100 (MET) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id PAA19198 for ; Thu, 28 Dec 2000 15:22:20 +0100 (MET) Received: from julie.univ-savoie.fr (univax.univ-savoie.fr [193.48.120.32]) by nez-perce.inria.fr (8.11.1/8.10.0) with ESMTP id eBSEMJL22352 for ; Thu, 28 Dec 2000 15:22:19 +0100 (MET) Received: from univ-savoie.fr (bppp4.univ-savoie.fr [193.48.120.23]) by julie.univ-savoie.fr (8.9.3/jtpda-5.3.3) with ESMTP id PAA17213 for ; Thu, 28 Dec 2000 15:22:12 +0100 (CET) Message-ID: <3A4BA041.F878C6BE@univ-savoie.fr> Date: Thu, 28 Dec 2000 15:19:13 -0500 From: Christophe Raffalli Organization: Laboratoire de =?iso-8859-1?Q?Math=E9matiques?=, =?iso-8859-1?Q?Universit=E9?= de Savoie X-Mailer: Mozilla 4.76 [fr] (X11; U; Linux 2.2.17-21mdk i686) X-Accept-Language: fr, en MIME-Version: 1.0 To: caml-list@inria.fr Subject: A proposal for overloading ... References: <4.3.2.7.2.20001226151428.00b2f680@shell16.ba.best.com> Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Sender: weis@pauillac.inria.fr 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