From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: weis Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id SAA28556 for caml-redistribution; Wed, 21 Apr 1999 18:58:22 +0200 (MET DST) Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id PAA10997 for ; Wed, 21 Apr 1999 15:14:30 +0200 (MET DST) Received: from morgon.inria.fr (morgon.inria.fr [128.93.8.33]) by concorde.inria.fr (8.8.7/8.8.7) with ESMTP id PAA05244; Wed, 21 Apr 1999 15:14:21 +0200 (MET DST) Received: (from remy@localhost) by morgon.inria.fr (8.8.7/8.8.7) id OAA27307; Wed, 21 Apr 1999 14:18:36 +0200 Message-ID: <19990421141836.40591@morgon.inria.fr> Date: Wed, 21 Apr 1999 14:18:36 +0200 From: Didier Remy To: Giuseppe Castagna Cc: caml-list@inria.fr, mottl@miss.wu-wien.ac.at Subject: Re: subtyping and inheritance Reply-To: Didier.Remy@inria.fr References: <3715D924.F50D6586@ens.fr> <19990420143806.33996@morgon.inria.fr> <371C97FE.B8B5010D@ens.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 0.85e In-Reply-To: <371C97FE.B8B5010D@ens.fr>; from Giuseppe Castagna on Tue, Apr 20, 1999 at 05:06:38PM +0200 Organization: INRIA, BP 105, F-78153 Le Chesnay Cedex Phone: (33) 1 3963 5317 -- Sec: (33) 1 3963 5570 -- Fax: (33) 1 3963 5684 Web: http://cristal.inria.fr/~remy Sender: weis > I completely agree, it is quite difficult (maybe impossible) to do it if you > want it fully general. Beppe, You won't be surprised if I tell you that I don't like special cases a lot. Moreover, I don't really know where and how to draw a clear border. Even on the particular example of money that you took, things are not so simple.... ---------------- Typechecking of classes in Ocaml is (relatively) simple because it relies only on polymorphism and not on subtyping. Subtyping comes later and it is not essential. In particular, if you never use explicit coercions, there is actually no subtyping involved at all, and most examples still typecheck, including binary methods (and much more)! As a result of this simple approach, the type of self in a subclass is just an instance of the type of self in its parent class. I suspect that you will have to give up this invariant since your approach is, conversely, based on subtyping and not on polymorphism. Then, you may be loosing much of the simplicity or just be unable to formalize the ``patch'' as an ``extension'' of Ocaml. > # class money2 x = > object > inherit money x > method dynamic leq (p:'mytype) = repr <= (p#value -. p#square) > method square = repr *. repr > end;; [the type annotation on "p" is useless you bound "'mytype" as the type of self in "object (_ : 'mytype)"] What type do you wish to give to that class? In particular, what should be the (static) type of an object of that class? > What the "dynamic" modifier means? First of all, it means that money2 is a > subtype of money (that is it allows contravariant occurrences of > 'mytype). Another essential matter is that type comparisons in Ocaml are structural, as opposed to by-name: this applies to both type equality and subtyping. Thus, you cannot just ``make'' money2 a subtype of money. Then, how would you define the subtyping relation so that the type money2 is a subtype of money? In conclusion, I think that even when restricting to a small subcase of the general problem the solution, if it exists as an extension of Ocaml, is not easy. In any case, I would be very happy to see it on paper... Cheers, -Didier