From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id VAA23754; Tue, 21 Sep 2004 21:27:44 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f 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 VAA24141 for ; Tue, 21 Sep 2004 21:27:42 +0200 (MET DST) Received: from swordfish.cs.caltech.edu (swordfish.cs.caltech.edu [131.215.44.124]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id i8LJRVGP006724 for ; Tue, 21 Sep 2004 21:27:32 +0200 Received: from orchestra.cs.caltech.edu (orchestra.cs.caltech.edu [131.215.44.20]) by swordfish.cs.caltech.edu (Postfix) with ESMTP id 979D7DF2F3; Tue, 21 Sep 2004 12:27:21 -0700 (PDT) Received: by orchestra.cs.caltech.edu (Postfix, from userid 2554) id 92B859BD95; Tue, 21 Sep 2004 12:27:19 -0700 (PDT) From: Michael Vanier To: garrigue@kurims.kyoto-u.ac.jp Cc: caml-list@inria.fr In-reply-to: <20040921.170339.118021840.garrigue@kurims.kyoto-u.ac.jp> (message from Jacques GARRIGUE on Tue, 21 Sep 2004 17:03:39 +0900 (JST)) Subject: Re: [Caml-list] Re: OCAML Downcasting? References: <20040921.170339.118021840.garrigue@kurims.kyoto-u.ac.jp> Message-Id: <20040921192719.92B859BD95@orchestra.cs.caltech.edu> Date: Tue, 21 Sep 2004 12:27:19 -0700 (PDT) X-Miltered: at nez-perce with ID 415080A3.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; vanier:01 mvanier:01 caml-list:01 downcasting:01 2004:99 jacques:01 oo-languages:01 downcasting:01 subtyping:01 subtyping:01 runtime:01 downcast:01 subtypes:01 subtypes:01 instanceof:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > Date: Tue, 21 Sep 2004 17:03:39 +0900 (JST) > From: Jacques GARRIGUE > > There are two important differences between ocaml and other > OO-languages that have downcasting. > > - inheritance is not subtyping. The subtyping relation being > structural, a full fledge typecast would not only require to keep > type information at runtime, but to embark a large part of the > compiler to check subtyping. This might also be incredibly slow. > > As a result, downcast is only reasonable when we have both > inheritance and subtyping. You're suddenly losing a large part of > the language. But java has interfaces (subtypes), and classes can implement interfaces (making them subtypes of the interface) without inheritance. Furthermore, the class identity can be retrieved from an instance of an interface by using the instanceof operator. > > Worse, even if you have a module interface > class b : > object > inherit a > .... > end > in ocaml this does _not_ mean that b inherits from a, just that it > has at least a's methods and fields. > So the semantics of downcast would not allow abstraction. I don't understand the point you're trying to make here, but it seems like a is effectively equivalent to an interface in java (at least from your description). > - classes may have type parameters. Assume a situation like > class ['a] a = object ... end > Then we cannot downcast any runtime object to "a", because we don't > know what is its type parameter. Again, downcast would not mix well > with other features of the language. Java now has generics (type parameters), and I assume that it has to get around this situation somehow. > > So, while this is somehow unfortunate, there is no downcast in ocaml. > I'm sure there are good reasons for this, but I don't find the arguments you've presented above persuasive. Not that I'm trying to hold java up as a shining example of the Right Thing; I'd much rather program in ocaml than java any day of the week. But the lack of downcasting has frustrated me in the past (it's my #1 gripe about ocaml, with the lack of support for native-code shared libraries at #2). Mike ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners