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 WAA15854 for caml-red; Wed, 25 Oct 2000 22:20:38 +0200 (MET DST) 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 VAA16194 for ; Wed, 25 Oct 2000 21:47:15 +0200 (MET DST) Received: from shell5.ba.best.com (shell5.ba.best.com [206.184.139.136]) by nez-perce.inria.fr (8.11.1/8.10.0) with ESMTP id e9PJlEj14299; Wed, 25 Oct 2000 21:47:14 +0200 (MET DST) Received: from localhost (bpr@localhost) by shell5.ba.best.com (8.9.3/8.9.2/best.sh) with ESMTP id MAA14294; Wed, 25 Oct 2000 12:47:08 -0700 (PDT) Date: Wed, 25 Oct 2000 12:47:08 -0700 (PDT) From: Brian Rogoff To: John Max Skaller cc: Tom Hirschowitz , caml-list@inria.fr Subject: Re: circular types? In-Reply-To: <39F6E831.621B85E3@ozemail.com.au> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: weis@pauillac.inria.fr On Thu, 26 Oct 2000, John Max Skaller wrote: > Brian Rogoff wrote: > > And if you can do that then allowing mutual recursion between > > classes and types also should be allowed. > > I think this can be done now. Here is the method: to have a type t > and a class c mutually dependent, for example: > > class type c = object x : t end > and type t = C c | Null > > write > > class type c' ['t] = object x : 't end > type t = C t c' | Null > class type c = t c' > > and you have it. In other words, abstract out the types from > the classes by making them type parameters, declare the types, > using appropriately instantiated class types, and then name the > required class instances. Yes, it's the same trick that I pointed out for module/type recursions; as they say any problem can be solved by another level of indirection. I'd like to be able to express this directly with an "and" of course. Check your syntax too, it's really class type ['a] c' = object method x : 'a end;; type t = C of t c' | Null;; class type c = object inherit [t] c' end;; and note that this works with virtual classes as well as class types class virtual ['a] c' = object method virtual x : 'a end;; type t = C of t c' | Null;; class virtual c = object inherit [t] c' end;; class foo a_t = object inherit c method x = a_t end;; let f0 = new foo Null;; let f1 = new foo (C f0);; Before anyone complains about those horrid double semi-colons I point out that those lines are all accepted by the top-level ;;-) -- Brian