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 OAA11433; Tue, 16 Jul 2002 14:45:21 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f 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 OAA11411 for ; Tue, 16 Jul 2002 14:45:20 +0200 (MET DST) X-SPAM-Warning: Sending machine is listed in blackholes.five-ten-sg.com Received: from athlon.baretta.com (r-mi214-6a44.tin.it [62.211.4.44]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g6GCjJb08575 for ; Tue, 16 Jul 2002 14:45:19 +0200 (MET DST) Received: from baretta.com (localhost.localdomain [127.0.0.1]) by athlon.baretta.com (Postfix) with ESMTP id B11002724F; Tue, 16 Jul 2002 14:52:23 +0200 (CEST) Message-ID: <3D341707.8020606@baretta.com> Date: Tue, 16 Jul 2002 14:52:23 +0200 From: Alessandro Baretta Organization: Baretta srl -- www.baretta.com User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.0) Gecko/20020529 X-Accept-Language: it, en MIME-Version: 1.0 To: =?ISO-8859-1?Q?Johan_Balti=E9?= , Ocaml Subject: Re: [Caml-list] Recovering masked methods (with CamlP4?) References: <3D335729.3020307@baretta.com> <20020716101520Q.garrigue@kurims.kyoto-u.ac.jp> <3D33E74C.6050307@baretta.com> <20020716095939.M27616@wanadoo.fr> <3D33FE98.6000001@baretta.com> <20020716113240.M56995@wanadoo.fr> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Johan Baltié wrote: > Uhh ? I have missed something. Can you forward me this post privately ? I cannot > find it. It seems awful to me to hear that inheritance is "syntactic", because > it does mean (for me) that nothing happen at runtime. > I've been looking for the exact post, but I can't find it. I remember distictly to have read something like that a little while ago, yet I cannot find the message. Anyhow, insofar as I have understood the workings of the Ojbective part of the Caml, class inheritance is merely supposed to be a form of type safe code reuse (something of a macroexpansion to use C/++ terminology). In C++, if class B inherits from class A, B *is an* A. In O'Caml this is not true. B has all the functionality (read, "methods") provided by A. Nowhere is it guaranteed to be either type-equivalent to or a subtype of A. Therefore, an instance of B cannot be used wherever an instance of A can be used. And even if B *is a subtype* of A, then instances of B must be explicitly coerced to having type A (this amounts to method hiding, AFAIK) before they can be used as actual parameters to funtions whose formal parameter is of type A. An example of this feature is Pxp's parse_document entity function. In order to check che validity of the use of ID and IDREF attribute fields in an XML document, the above function must be passed an object of type index = < {some_methods} >. But this is only a class type (an interface à la Java). Gerd Stolpmann provides an implementation class hash_index which is a sub_type of of index (implements the interface), but adds one extra method. In order to pass an object instance of hash_index to parse_document_entity you have to explicitly coerce it to having type index. This is why it is perfectly sensible to let class variant_of_b inherit from class b, although the two classes *are not* in an "is a" relation with one another. You get the benefit of inheriting all the code in b which is also needed in variant_of_b, all the while retaining the possibility of adding methods to variant_of_b such that variant_of_b *is not a* b. This approach to inheritance is radically different from that of C++. It takes a while to get the hang of it. It's actually much more powerful. Alex ------------------- 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