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 DAA14153; Fri, 9 Jul 2004 03:13:31 +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 DAA17223 for ; Fri, 9 Jul 2004 03:13:30 +0200 (MET DST) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by nez-perce.inria.fr (8.12.10/8.12.10) with ESMTP id i691DREV000765 for ; Fri, 9 Jul 2004 03:13:28 +0200 Received: from localhost (suiren.kurims.kyoto-u.ac.jp [130.54.16.25]) by kurims.kurims.kyoto-u.ac.jp (8.9.3p2-20030924/3.7W) with ESMTP id KAA22166; Fri, 9 Jul 2004 10:13:23 +0900 (JST) Date: Fri, 09 Jul 2004 10:13:23 +0900 (JST) Message-Id: <20040709.101323.82055376.garrigue@kurims.kyoto-u.ac.jp> To: szegedy@t-online.de Cc: caml-list@inria.fr Subject: Re: [Caml-list] Recursive class/class type From: Jacques GARRIGUE In-Reply-To: <40EDD11E.6030003@t-online.de> References: <40EDD11E.6030003@t-online.de> X-Mailer: Mew version 4.0.64 on Emacs 21.2 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Miltered: at nez-perce with ID 40EDF137.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 jacques:01 aliasing:01 closures:01 jacques:01 semantics:01 ocaml:01 garrigue:01 garrigue:01 interfaces:01 classes:03 classes:03 recursive:03 recursive:03 object:03 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk From: szegedy@t-online.de (Christian Szegedy) > I realiyed that I sometimes need not only recursive > classes but also mixed recursive types and interfaces. > > Something like this: > > class type a_t = > object > method f : a > end > and a = > object(self) > method f = self > method g (x:a_t) = x#f > end > > The current Ocaml implementation does not allows this. > Are there plans to allow types and class types in the same > recursive declaration block? Not really, while this might be possible. That is, mixing class types with classes, not either of them with ordinary types, as ordinary type definitions have different aliasing semantics. One way to avoid this restriction is to replace a_t by a virtual class. class virtual a_t = object method virtual f : a end and a = object(self) method f = self method g (x:a_t) = x#f end This defines the same class type a_t. This also generates some code for a_t, which is not needed, but the amount of code is very small: 2 closures and 2 function calls. Jacques Garrigue ------------------- 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