From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id 718FABBAF for ; Fri, 23 Oct 2009 18:15:03 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AlQBAJ9z4UrRVdrki2dsb2JhbACPYIFxiRw/AQEBCgsKBxEFrHuBO4ZjiGgBAwMFhDoE X-IronPort-AV: E=Sophos;i="4.44,613,1249250400"; d="scan'208";a="36901271" Received: from mail-bw0-f228.google.com ([209.85.218.228]) by mail3-smtp-sop.national.inria.fr with ESMTP; 23 Oct 2009 18:15:03 +0200 Received: by bwz28 with SMTP id 28so1145474bwz.17 for ; Fri, 23 Oct 2009 09:15:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:content-type:mime-version :subject:from:in-reply-to:date:content-transfer-encoding:message-id :references:to:x-mailer; bh=U8Y85OA0hZXrP7/soOwwe6ZrPazvLiDfaLAaAdUd6vU=; b=JM2wkV0uX9wgwcpnzSZH5+ZUcwDwjDQVC5vuLy+nThCK5qeIzKgzFw+ksWAvuCAuDX fExVTkgKegBH6t2S1vFPYEeUpcrD+cSU8a/G0FyfY4WaLTjWjhuEu1l66Q28F5cxSOMx dCTxFWEiopRjMjLIk8vL4gUkyweHZs608KvsY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=content-type:mime-version:subject:from:in-reply-to:date :content-transfer-encoding:message-id:references:to:x-mailer; b=I7v8l5CjcbstlHJz95zfFslXjPX3SGkOy2B4EpegA/8x5y0VgHPlgNjeRQwfRY+T1t fByOkNSMFBrtMmTu/ZjorsowIAfFlfaFx0nMsLn1AXMfl4scQc1mJEtz7Knj6dgqIrjt 1o9m9dXYXpkhVGrmjNym9fGMNQnO3iU+6Mguo= Received: by 10.204.156.28 with SMTP id u28mr10988031bkw.74.1256314502775; Fri, 23 Oct 2009 09:15:02 -0700 (PDT) Received: from ?192.168.0.11? (alf94-2-82-66-123-91.fbx.proxad.net [82.66.123.91]) by mx.google.com with ESMTPS id k29sm4157593fkk.55.2009.10.23.09.15.01 (version=TLSv1/SSLv3 cipher=RC4-MD5); Fri, 23 Oct 2009 09:15:01 -0700 (PDT) Content-Type: text/plain; charset=iso-8859-1; format=flowed; delsp=yes Mime-Version: 1.0 (Apple Message framework v1076) Subject: Re: [Caml-list] forbidden construct as right hand side of "let rec" From: Marc de Falco In-Reply-To: <200910231735142654782@orange.fr> Date: Fri, 23 Oct 2009 18:14:57 +0200 Content-Transfer-Encoding: quoted-printable Message-Id: References: <1256250121.4178.37.camel@MATHIAS-ENS>, <4AE0DDF5.8040601@glondu.net>, <4a708d20910221610w1c46fbbdk677e8545dcf3cd62@mail.gmail.com> <200910231735142654782@orange.fr> To: caml-list@inria.fr X-Mailer: Apple Mail (2.1076) X-Spam: no; 0.00; foo:01 foo:01 constructors:01 damien:01 guichard:01 damien:01 lukasz:01 beginner's:01 ocaml:01 bug:01 beginner's:01 ocaml:01 bug:01 2009:98 2009:98 The issue is that this definition can't be generalized to lists of =20 arbitrary size. The code let list_cycle l =3D let rec loop =3D l @ loop in loop will not be accepted. I don't know the exact rule, but I guess that on the right-hand side =20 of a let rec defining a ground value named foo you can only write a term =20 which evaluates to a finite ground term on the currently defined variables + =20= foo. That is to say something that evaluates to a finite tree of =20 constructors with constants or defined variables as leaves. Maybe someone more knowledgeable could state the exact rule. - marc P.S. : the code using Obj is far from a solution as it modifies the =20 existing structure of the list to add cycling and thus, breaks persistency. Le 23 oct. 2009 =E0 17:35, Damien Guichard a =E9crit : > > let list_cycle2 a b =3D > let rec loop =3D a::b::loop > in loop > > > - damien > > En r=E9ponse au message > de : Lukasz Stafiniak > du : 2009-10-23 01:10:37 > =C0 : caml-list > CC : > Sujet : Re: [Caml-list] forbidden construct as right hand side of =20 > "let rec" > > While we are at it, what is the best way to convert a "straight" list > into a cyclic list? > > i.e. convert > > let l =3D a::b::[] > > into > > let rec l =3D a::b::l > > (for arbitrary length lists). (The answer I recall from the archives > was using Obj.magic to mutate the [] in the original list). > > On Fri, Oct 23, 2009 at 12:34 AM, St=E9phane Glondu > wrote: > > Mathias Kende a =E9crit : > > > let rec g =3D f g > > > > What about: > > > > let rec g x =3D f g x > > _______________________________________________ > 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 > _______________________________________________ > 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