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 NAA32578; Thu, 23 May 2002 13:06:08 +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 NAA32610 for ; Thu, 23 May 2002 13:06:07 +0200 (MET DST) Received: from ebene.inrialpes.fr (ebene.inrialpes.fr [194.199.18.70]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g4NB66T11912 for ; Thu, 23 May 2002 13:06:06 +0200 (MET DST) Received: from pop-serv.inrialpes.fr (pop-serv.inrialpes.fr [194.199.18.66]) by ebene.inrialpes.fr (8.11.6/8.11.6) with ESMTP id g4NB4I422505 for ; Thu, 23 May 2002 13:04:18 +0200 (MEST) Received: from inrialpes.fr (cime.inrialpes.fr [194.199.23.76]) by pop-serv.inrialpes.fr (8.11.3/8.11.3/ImagV2) with ESMTP id g4NB4IG16686 for ; Thu, 23 May 2002 13:04:18 +0200 (MEST) Message-ID: <3CECCCB3.72B4ED20@inrialpes.fr> Date: Thu, 23 May 2002 13:04:19 +0200 From: Frederic Tronel X-Mailer: Mozilla 4.76 [en] (X11; U; SunOS 5.8 sun4u) X-Accept-Language: en MIME-Version: 1.0 To: caml-list@inria.fr Subject: Re: [Caml-list] A question about classes and multiple inheritance References: <3CECAD94.69976221@inrialpes.fr> <20020523185248D.garrigue@kurims.kyoto-u.ac.jp> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > By definition super is statically resolved, and self is dynamically > resolved. This is actually the point. I understood this point by tracking the path of a call to preBehavior. >In ocaml you don't get two > independent hierarchies of methods with multiple inheritance: methods > with same name are merged, taking implementation from last one. > The only way to get dynamic resolution is to go through self ("this"). > > But this seems to be what you are doing anyway, calling > this#localPreBehaviour. So what's the point in calling > super#preBehaviour? You certainly don't want to call yourself. > There's certainly some way to do what you are trying to do, but we > have to know what you want. > > If what you want is to call a localPreBehaviour for each superclass, > then it's difficult, because there's no real support for mixins, and > there's no keyword to say that a method should not appear in > subclasses. 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. But of course, I feel there is a problem in this (contrary to Java where super is unique) since ocaml supports multiple inheritance and the binding of superclasses is left to the programmer. A default "super" bound to the first inherited class (for example), dynamically resolved would help building nice applications of objects. Other scheme are certainly possible, but may lead to code that is difficult to maintain and understand. Anyway, for those who are interested, I have found the following way to solve the problem: class virtual behaviorSpecElement = object (this) method virtual localPreBehavior : (string,string) Hashtbl.t -> specBehavior method virtual superPreBehavior : (string,string) Hashtbl.t stack -> specBehavior method virtual preBehavior : (string,string) Hashtbl.t stack -> specBehavior end 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. Frederic. ------------------- 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