From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id D63B6BBAF for ; Fri, 21 May 2010 20:01:18 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AokDALVn9kvZSMDdi2dsb2JhbACeDBUBAQEKCwoHDwUfvVSFEgSPRA X-IronPort-AV: E=Sophos;i="4.53,279,1272837600"; d="scan'208";a="59826516" Received: from fmmailgate01.web.de ([217.72.192.221]) by mail1-smtp-roc.national.inria.fr with ESMTP; 21 May 2010 20:01:12 +0200 Received: from smtp02.web.de ( [172.20.0.184]) by fmmailgate01.web.de (Postfix) with ESMTP id 01D7015AC6DFF; Fri, 21 May 2010 20:01:12 +0200 (CEST) Received: from [78.43.204.177] (helo=frosties.localdomain) by smtp02.web.de with asmtp (TLSv1:AES256-SHA:256) (WEB.DE 4.110 #4) id 1OFWX0-0005FV-00; Fri, 21 May 2010 20:01:10 +0200 Received: from mrvn by frosties.localdomain with local (Exim 4.71) (envelope-from ) id 1OFWX7-0004LA-9g; Fri, 21 May 2010 20:01:17 +0200 From: Goswin von Brederlow To: Jacques Garrigue Cc: goswin-v-b@web.de, caml-list@yquem.inria.fr Subject: Re: [Caml-list] Problem with recursive class and non-class types References: <87mxvvma1r.fsf@frosties.localdomain> <20100520.163902.107127668.garrigue@math.nagoya-u.ac.jp> Date: Fri, 21 May 2010 20:01:17 +0200 In-Reply-To: <20100520.163902.107127668.garrigue@math.nagoya-u.ac.jp> (Jacques Garrigue's message of "Thu, 20 May 2010 16:39:02 +0900 (JST)") Message-ID: <87iq6hrv6a.fsf@frosties.localdomain> User-Agent: Gnus/5.110009 (No Gnus v0.9) XEmacs/21.4.22 (linux, no MULE) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: goswin-v-b@web.de X-Sender: goswin-v-b@web.de X-Provags-ID: V01U2FsdGVkX19XVqjkX02CreJLVsUsYi3JSx1i4xHhw7oBsz9y IcLa6DxhevuHhhxX8Zj3/uXmumcyW8OMi25E5f5VecpiRcHP27 DaBbGVl2M= X-Spam: no; 0.00; recursive:01 foo:01 val:01 mutable:01 foo:01 val:01 mutable:01 recursive:01 verbose:01 sig:01 struct:01 sig:01 mfg:98 rec:01 rec:01 Jacques Garrigue writes: > From: Goswin von Brederlow >> I want to define the two types below: >> >> type foo = { bar : bar; } >> class bar = object val mutable foo : foo list = [] end >> >> Is there another way of doing this other than: >> >> # type 'a foo = { bar : 'a; } >> class bar = object val mutable foo : #bar foo list = [] end;; >> type 'a foo = { bar : 'a; } >> class bar : object val mutable foo : #bar foo list end > > The alternative is to use a recursive module, but this is actually > more verbose. > > module rec M : sig > type foo = { bar : M.bar; } > class bar : object val mutable foo : foo list end > end = struct > type foo = { bar : M.bar; } > class bar = object val mutable foo : foo list = [] end > end > > You can avoid a bit of the verboseness by splitting types and values, > since recursive modules built only from types require no duplication. > > module rec M : sig > type foo = { bar : M.bar; } > class type bar = object val mutable foo : foo list end > end = M > > class bar : M.bar = object val mutable foo : M.foo list = [] end > > You still need to provide an explicit interface for bar. > > Hope this helps, > > Jacques Garrigue Thanks, it does. It isn't nice but it does solve the problem. Now I have to decide what I live with. 'a foo uglyness or module rec uglyness. It is too bad a simple type foo = ... and class bar = ... doesn't work. MfG Goswin