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 RAA30217 for caml-redistribution; Thu, 15 Apr 1999 17:47:49 +0200 (MET DST) 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 OAA26563 for ; Thu, 15 Apr 1999 14:19:20 +0200 (MET DST) Received: from nef.ens.fr (nef.ens.fr [129.199.96.12]) by nez-perce.inria.fr (8.8.7/8.8.7) with ESMTP id OAA09195 for ; Thu, 15 Apr 1999 14:19:19 +0200 (MET DST) Received: from reglisse.ens.fr (reglisse.ens.fr [129.199.98.59]) by nef.ens.fr (8.9.3/beig-1.0) with ESMTP id OAA29911 ; Thu, 15 Apr 1999 14:18:47 +0200 (MET DST) Received: from ens.fr (localhost [127.0.0.1]) by reglisse.ens.fr (8.9.2/jb-1.1) id OAA12920 ; Thu, 15 Apr 1999 14:18:46 +0200 (MET DST) Sender: weis Message-ID: <3715D924.F50D6586@ens.fr> Date: Thu, 15 Apr 1999 14:18:44 +0200 From: Giuseppe Castagna X-Mailer: Mozilla 4.51 [en] (X11; I; SunOS 5.6 sun4u) X-Accept-Language: en MIME-Version: 1.0 To: caml-list@inria.fr CC: mottl@miss.wu-wien.ac.at Subject: Re: subtyping and inheritance Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sorry to reopen a thread that is more than 2 months old, but I'm not on the Caml-List and just today Hugo Herbelin hinted me that some of my work has been discussed on it. So let me add my two cents worth contribution. > [...] > > So far it seems that things would be unsafe with covariance. But now, > > Castagna answers my (former) question, whether making "reappear" methods > > from ancestors would be safe: it is... > > > > The paper looked difficult at first, but turned out to be surprisingly > > easy to read: Castagna makes the theorie very intuitively clear with his > > examples of classes "2DPoint" and "3DPoint" and how methods are chosen > > in the different models. > > > > The record based method (as found in OCAML - the object (record) > > determines, which method is selected, arguments are not considered) > > can be obviously extended to support covariance. > > However, it is not possible to apply this extension to Ocaml. Indeed, > it requires that methods are chosen depending on the dynamic type of > their arguments. But this information is not available in Ocaml. > There are also difficulties for type inference. Jerome is right when he says that dynamic type information is not available in Ocaml. Nevertheless I would not be so sure that this means that it is not possible to apply this extension to Ocaml. Surely, it would require some modifications to the compiler, but all it would have to do is to mark some particular methods and all the objects that could call these methods by a natural number (for those who know, some sort of De Brujin notation, that a purist may consider as dynamic type information). How to do it in practice is described for the language O2 in [1] (but without the natural numbers since in O2 the dynamic type information is available). This is obtained by simply modifying the compiler without affecting the language. Furthermore if you do not mind to extend the language (notice I said "extend" and not "modify") then you can do very nice things. This has been done AND implemented for Java. The extension of Java by "encapsulated multi-methods" (that's how we christened them) is described in [2]. This is obtained by simply adding a modifier to Java's syntax. We also have a compiler under Solaris that compiles this Java extension. It is interesting to note that it is a conservative extension of Java, which simply means that if you feed the extended compiler by a standard Java program you will obtain the same code as with the standard compiler (well, not exactly, object structures will have an extra useless slot). Let me end with some advertising. Both references should be much easier to read than the paper of mine cited in the previous messages. They can be retrieved at http://www.dmi.ens.fr/~castagna/pub.html If somebody would like to try to implement it in OCaml I'm ready to help him on the design part (e.g. a student looking for a subject for master thesis ;-) Cheers ---Beppe--- [1] J.Boyland and G. Castagna. Type-Safe Compilation of Covariant Specialization: A Practical Case. In Proc. of ECOOP'96. Lecture Notes in Computer Science, 1098:3-25, 1996. [2] J. Boyland and G. Castagna. Parasitic methods: an implementation of multi-methods for Java. In Proc. of OOPSLA'97. SIGPLAN Notices 32(10):66-76. 1997 P.S. We did not made the compiler public available. So there is no doc, etc., etc. ...