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 1266FBBAF for ; Thu, 20 May 2010 09:39:42 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AjgFALuD9EuFBoIF/2dsb2JhbACRdI0BrjKOEgEEhRKDQg X-IronPort-AV: E=Sophos;i="4.53,270,1272837600"; d="scan'208";a="59697563" Received: from rabbit.math.nagoya-u.ac.jp (HELO mailhost.math.nagoya-u.ac.jp) ([133.6.130.5]) by mail1-smtp-roc.national.inria.fr with ESMTP; 20 May 2010 09:39:40 +0200 Received: from mailhost.math.nagoya-u.ac.jp (localhost [127.0.0.1]) by mailhost.math.nagoya-u.ac.jp (Postfix) with ESMTP id F11FCB759; Thu, 20 May 2010 16:39:14 +0900 (JST) Received: from mailhost.math.nagoya-u.ac.jp (camel-172 [172.16.254.4]) by mailhost.math.nagoya-u.ac.jp (Postfix) with ESMTP id AC93088AD; Thu, 20 May 2010 16:39:14 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=math.nagoya-u.ac.jp; h= date:message-id:to:cc:subject:from:in-reply-to:references :mime-version:content-type:content-transfer-encoding; s=alpha; bh=Tu76mOWyP59/zIDiubo7Yaq1vSQ=; b=fH07aXlXc/C0xkClROc07nuiIyor AIKTbo3cA48VZ0u4fvsbwO9KUqJs1GGQgFN1i6OURXY7s3gagm6vVN35faLiIi7+ 3VdQtD2ySyxLuT4X+0lE9HlcijINdre7Abe+oPIWl3cawGL2BK755WXQyeovIRJ5 xHxR/2Pz/Xu1dvM= DomainKey-Signature: a=rsa-sha1; h=Received:Date:Message-Id:To:Cc:Subject:From:In-Reply-To:References:X-Mailer:Mime-Version:Content-Type:Content-Transfer-Encoding; b=wb39xLvzvk0YNokzIoH/NN9SzGlTGYUeRFM+YtKu8pYm8W9dMRFWu30X/X0JpQTOkHd0tcaXKNvQUCWgxSVJ1rO2FpHbVBp141hl0cChb66D23UKbrfvuRIUyMn+w/aDvrKsq6B/OmF99Egxmh+hMEc6Dt2ieD4NdYQ2S+FZdTk=; c=nofws; d=math.nagoya-u.ac.jp; q=dns; s=alpha Received: from localhost (bsdserver02 [172.16.249.2]) by mailhost.math.nagoya-u.ac.jp (Postfix) with ESMTP id 755A78894; Thu, 20 May 2010 16:39:14 +0900 (JST) Date: Thu, 20 May 2010 16:39:02 +0900 (JST) Message-Id: <20100520.163902.107127668.garrigue@math.nagoya-u.ac.jp> To: goswin-v-b@web.de Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Problem with recursive class and non-class types From: Jacques Garrigue In-Reply-To: <87mxvvma1r.fsf@frosties.localdomain> References: <87mxvvma1r.fsf@frosties.localdomain> X-Mailer: Mew version 6.3 on Emacs 22.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit 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 rec:01 rec:01 caml-list:01 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