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 LAA22348; Mon, 3 Nov 2003 11:46:38 +0100 (MET) 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 LAA22106 for ; Mon, 3 Nov 2003 11:46:37 +0100 (MET) Received: from avalon.ens-lsh.fr (mailhost.ens-lsh.fr [193.51.131.2]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id hA3Aka119921 for ; Mon, 3 Nov 2003 11:46:36 +0100 (MET) Received: from avalon.ens-lsh.fr (localhost [127.0.0.1]) by avalon.ens-lsh.fr (8.12.8/8.12.8) with ESMTP id hA3BkSMw013889 for ; Mon, 3 Nov 2003 11:46:29 GMT Received: from ens-notes1.ens-lsh.fr (ens-notes1.ens-lsh.fr [10.2.1.44]) by avalon.ens-lsh.fr (8.12.8/8.12.8) with ESMTP id hA3BkSaA013886 for ; Mon, 3 Nov 2003 11:46:28 GMT Received: from mostha ([10.3.20.31]) by ens-notes1.ens-lsh.fr (Lotus Domino Release 5.0.10) with SMTP id 2003110311463294:12342 ; Mon, 3 Nov 2003 11:46:32 +0100 Date: Mon, 3 Nov 2003 11:48:16 +0100 From: Damien To: caml-list@inria.fr Subject: [Caml-list] Mutually recursive classes Message-Id: <20031103114816.50edea0c.Damien.Pous@ens-lyon.fr> Organization: mosthagloups X-Mailer: Sylpheed version 0.9.6claws (GTK+ 1.2.10; i386-pc-linux-gnu) Mime-Version: 1.0 X-MIMETrack: Itemize by SMTP Server on ens-notes1/ENS-LSH(Release 5.0.10 |March 22, 2002) at 03/11/2003 11:46:32, Serialize by Router on ens-notes1/ENS-LSH(Release 5.0.10 |March 22, 2002) at 03/11/2003 11:46:34, Serialize complete at 03/11/2003 11:46:34 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII X-Loop: caml-list@inria.fr X-Spam: no; 0.00; damien:01 damien:01 ens-lyon:01 'self:01 'self:01 work-around:01 coerce:01 coerce:01 inherit:01 inherit:01 hierarchy:02 classes:03 classes:03 recursive:03 recursive:03 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hello, I would like to create two mutually recursive classes, parents (a) and children (b) Furthermore, I'd like to define them incrementally parents and children, parents and children with hands parents and children with hands and feet ... let's have a try : class type ['b] a0 = object ('a) method coerce: 'a method b: 'b constraint 'b = 'a #b0 (* ... *) end and ['a] b0 = object ('b) method coerce: 'b method a: 'a constraint 'a = 'b #a0 (* ... *) end class type ['b] a1 = object ('a) inherit ['b] a0 constraint 'b = 'a #b1 (* ... *) end and ['a] b1 = object ('b) inherit ['a] b0 constraint 'a = 'b #a1 (* ... *) end ... Unfortunately, this does not work : > constraint 'b = 'a #b0 > ^^ >This type < b : 'b; coerce : 'a; .. > as 'a should be an instance of >type 'c >Self type cannot escape its class which is odd from my mind, since the following code is well typed : class type ['c] c = object method c: 'c end class type ['b] a = object ('a) method b: 'b constraint 'b = 'a #c end I can get something better, using two type parameters : class type ['a, 'b] a0 = object method coerce: 'b method b: 'b constraint 'a = ('a, 'b) #a0 constraint 'b = ('a, 'b) #b0 end and ['a, 'b] b0 = object method coerce: 'b method a: 'a constraint 'a = ('a, 'b) #a0 constraint 'b = ('a, 'b) #b0 end but then the "self type" is no longer correlated to 'a/'b so that I can't implement the method coerce, so, I need to "virtualize" it, and to implement it only at the end of the class hierarchy, where I need to close it, saying 'a = 'self / 'b = 'self I don't want this, because I'd like be able to use these classes at any level (yes, a parent without feet does make sense...) Does this case of "Self type cannot escape its class" restriction really make sense ? Do you know how to work-around this ? thanks, damien ------------------- 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