From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id QAA02273 for caml-redistribution; Tue, 3 Nov 1998 16:55:47 +0100 (MET) 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 KAA05524 for ; Mon, 2 Nov 1998 10:30:25 +0100 (MET) Received: from julie.univ-savoie.fr (univax.univ-savoie.fr [193.48.120.32]) by nez-perce.inria.fr (8.8.7/8.8.7) with ESMTP id KAA11643 for ; Mon, 2 Nov 1998 10:30:24 +0100 (MET) Received: from univ-savoie.fr (raffalli@lama-d134.univ-savoie.fr [193.48.123.134]) by julie.univ-savoie.fr (8.9.0/jtpda-5.2) with ESMTP id KAA13861 for ; Mon, 2 Nov 1998 10:32:00 +0100 (MET) Sender: weis Message-ID: <363D7C18.FE3FB555@univ-savoie.fr> Date: Mon, 02 Nov 1998 10:32:08 +0100 From: Christophe Raffalli Organization: =?iso-8859-1?Q?Université?= de Savoie X-Mailer: Mozilla 4.5 [en] (X11; I; Linux 2.0.33 i586) X-Accept-Language: en MIME-Version: 1.0 To: caml-list@inria.fr Subject: Sharing inheritance ? Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit I have a problem with the following situation: --- class a (x : int) = object val mutable v = x method get = v method set x = v <- x end ;; class b x = object (self) inherit a x as super method getb = self#get method setb = self#set method oldget = super#get end ;; class c x = object (self) inherit a x method getc = self#get method setc = self#set end ;; class d x = object inherit b x inherit c x end ;; (* produces: Warning: the following methods are overriden by the inherited class: get set Warning: this definition of an instance variable v hides a previously defined instance variable of the same name *) let o = new d 2;; o#setb 3;; o#getc;; (* produces 3 *) o#oldget;; (* produces 2 *) --- I understand what is happening, but I would prefer is the default semantic was two merge two values with the same name in an object (giving a type error if their types can not unify). Then one could have a syntactic sugar to change the name of some value: class d x = object inherit b x inherit c x with v -> v' end ;; To ask to rename the value v from b as v'. Together with the possibility to bind a name to acces old method, this will allow a total flexibility (I can always do what I want) which is not the case now. --- Moreover, the follwing would become possible: class d = object inherit b 0 with v -> v0 as b0 inherit b 1 with v -> v1 as b1 inherit b 2 with v -> v2 as b2 end ;; Christophe Raffalli Universite de Savoie PS: do not forget to add "inherit" and "open ... in" for structure in the next release, that will make some program simpler.