From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id A0C75BB91 for ; Thu, 16 Dec 2004 16:00:22 +0100 (CET) Received: from mail.broadpark.no (mail.broadpark.no [217.13.4.2] (may be forged)) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id iBGF0MU7016227 for ; Thu, 16 Dec 2004 16:00:22 +0100 Received: from h2o.hex.no (mail.hex.no [80.203.227.205]) by mail.broadpark.no (Postfix) with ESMTP id C95FC191F for ; Thu, 16 Dec 2004 15:59:08 +0100 (MET) Received: from localhost (localhost [127.0.0.1]) (uid 1000) by h2o.hex.no with local; Thu, 16 Dec 2004 15:59:07 +0100 id 001A690F.41C1A2BB.00003D6C Date: Thu, 16 Dec 2004 15:59:07 +0100 From: "=?iso-8859-1?Q?J=F8rgen?= Hermanrud Fjeld" To: caml-list@yquem.inria.fr Subject: Possibility of Nested Classes and Nested Inheritance? Message-ID: <20041216145907.GB5599@hex.no> Mail-Followup-To: caml-list@yquem.inria.fr Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="=_h2o-15724-1103209147-0001-2" Content-Disposition: inline User-Agent: Mutt/1.5.6+20040907i X-Miltered: at nez-perce with ID 41C1A306.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; scalable:01 ocaml:01 polymorphism:01 implicitly:01 enclosing:01 polymorphism:01 ocaml:01 threads:01 parametric:01 o'caml:01 gpg:01 myers:98 ...:98 ...:98 myers:98 X-Attachments: type="application/pgp-signature" name="signature.asc" X-Spam-Checker-Version: SpamAssassin 3.0.0 (2004-09-13) on yquem.inria.fr X-Spam-Status: No, score=0.1 required=5.0 tests=FORGED_RCVD_HELO autolearn=disabled version=3.0.0 X-Spam-Level: This is a MIME-formatted message. If you see this text it means that your E-mail software does not support MIME-formatted messages. --=_h2o-15724-1103209147-0001-2 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi,=20 I just read about the work by Nystrom, Chong and Myers on nested inheritance, specifically the article "Scalable Extensibility via Nested Inheritance". The article does demonstrate fascinating, to me, use of inheritance, and I wonder if it is possible to do something similar and object-oriented in O= Caml. To do something similar would, according to my understanding, require both inner classes and super-class polymorphism. In understand inner classes as implicitly polymorphic with respect to the e= nclosing class, and polymorphism on the super class as the practical ability to extend the type hierarchy upwards. Do you know of any work that relate nested inheritance to OCaml, or that address the similar issuesof inner classes and super-class polymorphism? I have tried to search the mailing list history, but I have not found relevant threads for these issues. It seems to me that inner classes can always be written as parametric classes, which means that OCaml could easily support inner classes.=20 Is this correct? Are there other intrinsic reasons why OCaml does not have inner classes, except of course that it would take an effort to implement, which I understand. Super-class polymorphism seems like a different beast, and I would very much appreciate any ideas, especially theoretical ideas, on how that=20 would interact with the OCaml type system. I imagine the following OCaml'ish example: class a =3D class b =3D object ... end class c =3D object inherit b ... end object ... end class d =3D class b' =3D object inherit b ... end (* The following is implicit class c' =3D object inherit b inherit b' inherit c ... end *) object inherit a ... end The inner classes are parametrised by the outer class, thus for the class a this could be written instead: class a =3D object ... end class ['a] b =3D object ... end class ['a] c =3D object inherit ['a] b ... end Here i use 'a because the examples is from a nominal type system,=20 as the name 'a suggests, although this is just coincidental for O'Caml. The class d is not such a clear case to write out, here is a try: class d =3D object inherit a ... end class ['d] b' =3D object inherit ['d] b ... end (* The following is implicit class ['d] c' =3D=20 object=20 inherit ['d] b'=20 inherit ['d] c=20 ...=20 end=20 *) It is this implicit part that I suspect could use super-class polymorphism, because then the class c could be rewritten as: class ['a,'b] c =3D=20 object=20 inherit ['a] 'b=20 ...=20 end and then the class c' would be the same as c, except that c'=20 is parametrised by [d,b'], while c is parametrised by [a,b]. With name shadowing of classes and explicit polymorphism=20 code could be written as: class a =3D class ['a] b =3D object ... end class ['a,'b] c =3D object inherit 'b ... end object ... end class d =3D class ['a] b =3D object inherit b ... end (* The following is implicit because b is connected to 'b by magic ;-) class ['a,'b] =3D object inherit b' ... end=20 *) object inherit a ... end I hope this demonstrates the idea. The following code is from the paper by Nystrom, Chong and Myers,=20 to give a sample of their intuition: class A { class B { int x; } class C extends B {...} int m(B b) { return b.x } C n() { return new C(); } } class A2 extends A { class B {int y; }=20 int m(B b) {return b.x + b.y } } --=20 Sincerely | Homepage: J=F8rgen | http://www.hex.no/jhf | Public GPG key: | http://www.hex.no/jhf/key.txt Mystics always hope that science will some day overtake them. -- Booth Tarkington --=_h2o-15724-1103209147-0001-2 Content-Type: application/pgp-signature; name="signature.asc" Content-Transfer-Encoding: 7bit Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (GNU/Linux) iD8DBQFBwaK79jvTqPy5VsoRAsL6AJ9MpXWIACVo+oGLwpFAzlmtHzGqaACeOi4n KZeS5Cg3aDVZ07JwX9LEIoM= =DJQR -----END PGP SIGNATURE----- --=_h2o-15724-1103209147-0001-2--