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 CAA14396; Fri, 24 May 2002 02:30:02 +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 CAA14176 for ; Fri, 24 May 2002 02:30:01 +0200 (MET DST) Received: from favie.faith.gr.jp (favie.faith.gr.jp [61.127.175.250]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g4O0TxD21995 for ; Fri, 24 May 2002 02:29:59 +0200 (MET DST) Received: from localhost (dhcp7.faith.gr.jp [192.168.1.17]) by favie.faith.gr.jp (8.9.3/8.9.3) with ESMTP id JAA13015; Fri, 24 May 2002 09:29:50 +0900 To: Frederic.Tronel@inrialpes.fr Cc: caml-list@inria.fr Subject: Re: [Caml-list] A question about classes and multiple inheritance In-Reply-To: <3CECCCB3.72B4ED20@inrialpes.fr> References: <3CECAD94.69976221@inrialpes.fr> <20020523185248D.garrigue@kurims.kyoto-u.ac.jp> <3CECCCB3.72B4ED20@inrialpes.fr> X-Mailer: Mew version 1.94.2 on Emacs 21.2 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-Id: <20020524092945Y.garrigue@kurims.kyoto-u.ac.jp> Date: Fri, 24 May 2002 09:29:45 +0900 From: Jacques Garrigue X-Dispatcher: imput version 20000228(IM140) Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk From: Frederic Tronel > Each subclass override the definition of localPreBehavior, and I want > preBehavior to call first this#localPreBehavior, and then in turn > preBehavior method of its upper class (single inheritance), > until it reaches the top level in the hierarchy. > This is the way it's done in Java for example. > For this to be simple, I need "super" to be resolved dynamically. I think you're confused. "super" is certainly resolved statically in Java too: try to use super.preBehaviour when your parent class doesn't define preBehaviour. Except maybe smalltalk, I believe super always refer to the parent class of the class in which you are defining yur method. abstract class A { abstract void m(); } class B extends A { void m () { super.m(); } } Test.java:7: abstract method m() cannot be accessed directly super.m(); ^ The problem only appears if you are using mixins, but Java has no mixins, and ocaml multiple inheritance does not really support them either. Remark also that in many cases use of higher-order functions and lists of function can provide a very clean non-oo solution to this kind of problem. > and virtual ['a] specElement = > fun (synchroAccounting : 'a) -> > object (this) > method superPreBehavior bindings = Null (* dummy definition *) > method preBehavior bindings = > let binding = bindings#top in > let myPre = this#localPreBehavior binding in > bindings#popSP ; > let superPre = this#superPreBehavior bindings in > bindings#pushSP ; > .... > end > > For each subclasses of specElement I define: > > method superPreBehavior = super#preBehavior > > It reduces the code duplication to this single definition. I don't understand what you are trying to do. Since superPreBehaviour is not hidden, this will only recurse once: you might call super#preBehaviour through superPreBehaviour, but in the superclass you will be calling the same superPreBehaviour, not super#super#preBehaviour as you seem to be expecting. Jacques ------------------- 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