Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] A question about classes and multiple inheritance
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2002-05-24 (00:30)
From: Jacques Garrigue <garrigue@k...>
Subject: Re: [Caml-list] A question about classes and multiple inheritance
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

abstract class A {
    abstract void m();

class B extends A {
    void m () {
} abstract method m() cannot be accessed directly
The problem only appears if you are using mixins, but Java has no
mixins, and ocaml multiple inheritance does not really support them

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

> 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.

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: