Re: subtyping and inheritance

From: Giuseppe Castagna (Giuseppe.Castagna@ens.fr)
Date: Thu Apr 15 1999 - 14:18:44 MET DST


Date: Thu, 15 Apr 1999 14:18:44 +0200
From: Giuseppe Castagna <Giuseppe.Castagna@ens.fr>
To: caml-list@inria.fr
Subject: Re: subtyping and inheritance

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. ...



This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:22 MET