From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: * X-Spam-Status: No, score=1.4 required=5.0 tests=AWL,DNS_FROM_RFC_POST, HTML_MESSAGE,SPF_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 35C8FBB84 for ; Mon, 14 Jul 2008 19:57:38 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Am4CAIIwe0jRVaK0eGdsb2JhbACCNwU1jnpDAQwDBAYHEQOTYIUJ X-IronPort-AV: E=Sophos;i="4.30,360,1212357600"; d="scan'208";a="27312396" Received: from el-out-1112.google.com ([209.85.162.180]) by mail4-smtp-sop.national.inria.fr with ESMTP; 14 Jul 2008 19:57:37 +0200 Received: by el-out-1112.google.com with SMTP id y26so805181ele.21 for ; Mon, 14 Jul 2008 10:57:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:cc:in-reply-to:mime-version:content-type:references; bh=IcUICViCWDD/sHgeDjAZJxjoH1MTqDYatuMqYZcrukE=; b=QRG5nFYr6nRliZRbO21w7yXQMiy4baU1AmUwmFzu/hRa6yPJiADmLan6GJKmzzh5Qk rkX8Obm516TD8CAHx4Lu28zMBkql+aVEo884n3SvKpN0lR9tn6zNP0GPO0BVq9UA67Z+ z6lk+QdshAWQKSTvXfT7Vy2pq4FD4AFcHmDfk= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version :content-type:references; b=vV+16kWsdicCOSPtHPHZSi9LJQ38dYsxEMqWZmpPDG4vCxnq8TRNUPcsknRsNEbGj5 mR+569M1gbAnqmdpRHtzi/llCELeOgtwjDspmnn/jNFAnaektVUdlz9xiG9CHQJlxJdT h+/IvJrpxOInnyK8RjvD1tBc4c+mrnYaKEHic= Received: by 10.151.45.2 with SMTP id x2mr11496975ybj.165.1216058256595; Mon, 14 Jul 2008 10:57:36 -0700 (PDT) Received: by 10.151.108.18 with HTTP; Mon, 14 Jul 2008 10:57:36 -0700 (PDT) Message-ID: <74cabd9e0807141057u64b31518h49627afb30de5503@mail.gmail.com> Date: Mon, 14 Jul 2008 10:57:36 -0700 From: "Arthur Chan" To: "Jon Harrop" Subject: Re: [Caml-list] Mutually recursive types in different modules Cc: caml-list@yquem.inria.fr In-Reply-To: <200807141804.32640.jon@ffconsultancy.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_94950_29566520.1216058256496" References: <1216054202.29061.2.camel@andre.mz.digirati.com.br> <200807141804.32640.jon@ffconsultancy.com> X-Spam: no; 0.00; recursive:01 achieves:01 recursive:01 foo:01 ocaml:01 recursion:01 polymorphism:01 beginner's:01 ocaml:01 bug:01 achieves:01 foo:01 recursion:01 beginner's:01 bug:01 X-Attachments: cset="UTF-8" cset="UTF-8" ------=_Part_94950_29566520.1216058256496 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline As Jon demonstrates it is "possible," but I do not think it truly achieves what you are trying to do. What is your use case? I do not recommend trying to make types recursive across modules. Even recursively defined modules have reared their ugly end on me. It is equivalent to writing non-orthogonal code, in the functional paradigm (see Pragmatic Programmer). On Mon, Jul 14, 2008 at 10:04 AM, Jon Harrop wrote: > On Monday 14 July 2008 17:50:02 Andre Nathan wrote: > > Hello > > > > Say I have the following type definition: > > > > type a = { x: int; foo: b } and b = { y: int; bar: a } > > > > Is it possible to define types a and b in their own files (thus in > > modules A and B) and still allow them to be mutually recursive? > > Yes. See the OCaml Journal article "Tricks with recursion: knots, modules > and > polymorphism" or Google for the phrase "untying the recursive knot". > > -- > Dr Jon D Harrop, Flying Frog Consultancy Ltd. > http://www.ffconsultancy.com/products/?e > > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > -- ----------------------------------------------------------------------- (\__/) (='.'=)This is Bunny. Copy and paste Bunny into your (")_(")signature to help him gain world domination. ------------------------------------------------------------------------ ------=_Part_94950_29566520.1216058256496 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline As Jon demonstrates it is "possible," but I do not think it truly achieves what you are trying to do.  What is your use case?  I do not recommend trying to make types recursive across modules.  Even recursively defined modules have reared their ugly end on me.  It is equivalent to writing non-orthogonal code, in the functional paradigm (see Pragmatic Programmer).



On Mon, Jul 14, 2008 at 10:04 AM, Jon Harrop <jon@ffconsultancy.com> wrote:
On Monday 14 July 2008 17:50:02 Andre Nathan wrote:
> Hello
>
> Say I have the following type definition:
>
>   type a = { x: int; foo: b } and  b = { y: int; bar: a }
>
> Is it possible to define types a and b in their own files (thus in
> modules A and B) and still allow them to be mutually recursive?

Yes. See the OCaml Journal article "Tricks with recursion: knots, modules and
polymorphism" or Google for the phrase "untying the recursive knot".

--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/products/?e

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs



--
-----------------------------------------------------------------------
(\__/)
(='.'=)This is Bunny. Copy and paste Bunny into your
(")_(")signature to help him gain world domination.
------------------------------------------------------------------------ ------=_Part_94950_29566520.1216058256496--