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.0 required=5.0 tests=AWL,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 mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id 69119BBCA for ; Tue, 26 Feb 2008 15:56:20 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAABO3w0fAXQImh2dsb2JhbACQYwEBAQgKKZRCh1A X-IronPort-AV: E=Sophos;i="4.25,407,1199660400"; d="scan'208";a="7724051" Received: from discorde.inria.fr ([192.93.2.38]) by mail2-smtp-roc.national.inria.fr with ESMTP; 26 Feb 2008 15:56:20 +0100 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id m1QEuFSJ000683 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Tue, 26 Feb 2008 15:56:20 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAABO3w0dIDvb4f2dsb2JhbACQYwEBCQQFCAoRBZREh1A X-IronPort-AV: E=Sophos;i="4.25,407,1199660400"; d="scan'208";a="23065680" Received: from ag-out-0708.google.com ([72.14.246.248]) by mail4-smtp-sop.national.inria.fr with ESMTP; 26 Feb 2008 15:56:19 +0100 Received: by ag-out-0708.google.com with SMTP id 9so5731602agd.9 for ; Tue, 26 Feb 2008 06:56:18 -0800 (PST) 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:content-transfer-encoding:content-disposition:references; bh=oXecdh1MDsh6bYMjetN2bu3O21OO6qZq1K09QtPdPgo=; b=Yw2KgEvSSMOwyTbCId5JlSg9RRykFrc5S9FYOvPkp8tBx2Y9bj+cCssthH7j1ChXBW0X0xjFSJjmQi6urXWBdi7zQWCY7f5NlDpo2mFvwJKfDcQ4O+YQXgESTaNm1F8/Ybn8RUfhZhJK5g8sSK7xTAI6t83l/LALQHK+qwJ3/MY= 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:content-transfer-encoding:content-disposition:references; b=ekk/qSz+FzQsa5wVkoic3W2iEn6pp8epFhWIL9PEvvEFcIuYlGOLl/WE1guhL/1h+1dxQ/2JX41Zj6//zKbZN8PpMHlJ8/VZgUpmvEHPdSCMmFQeEWJbYZIT3DhGzhiDyQvN8S4pOh2Vl4VE8KRmSobBC2WgXNwTE4MhdJKgcmU= Received: by 10.142.154.20 with SMTP id b20mr3682821wfe.150.1204037776689; Tue, 26 Feb 2008 06:56:16 -0800 (PST) Received: by 10.142.173.15 with HTTP; Tue, 26 Feb 2008 06:56:16 -0800 (PST) Message-ID: <527cf6bc0802260656k51cbf486icdf01ac4786c2993@mail.gmail.com> Date: Tue, 26 Feb 2008 15:56:16 +0100 From: "blue storm" To: "Loup Vaillant" Subject: Re: [Caml-list] Unexpected restriction in "let rec" expressions Cc: "Damien Doligez" , "Caml List" In-Reply-To: <6f9f8f4a0802260634j133a6b5fl1868c6886f308c1b@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <6f9f8f4a0802260424o5bce2fd9i89fbfa38bb239a6a@mail.gmail.com> <958FA43C-037A-47D3-9352-682443875A69@inria.fr> <6f9f8f4a0802260634j133a6b5fl1868c6886f308c1b@mail.gmail.com> X-Miltered: at discorde with ID 47C4288F.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; haskell:01 ocaml:01 translated:01 ocaml:01 damien:01 damien:01 recursive:01 val:01 fixpoint:01 beginner's:01 bug:01 storm:98 26,:98 doligez:01 doligez:01 Your "loop" function looks similar to some concepts of "Circular programming" ( http://www.haskell.org/haskellwiki/Circular_programming ). I've been interested in the translation of such code into OCaml a few weeks ago, and i came with a different solution, wich use lazy evaluation (of course there may be a better way to do it) : let trace f input = let rec out_feed = lazy (f (input, lazy (snd (Lazy.force out_feed)))) in let a = Lazy.force out_feed in fst a The returned type (('a * 'b lazy_t -> 'c * 'b) -> 'a -> 'c) express the fact that the input tuple is lazy on its second parameter. Here is the repIImin example, translated into OCaml : type 'a tree = Leaf of 'a | Branch of ('a tree * 'a tree) let repIImin tree = let rec repIImin' = function | Leaf r, min -> lazy (Leaf (Lazy.force min)), r | Branch (a, b), mini -> let (a', mina) = repIImin' (a, mini) in let (b', minb) = repIImin' (b, mini) in lazy (Branch (Lazy.force a', Lazy.force b')), (min mina minb) in Lazy.force (trace repIImin' tree) However, i'm not sure this example is very useful. The intended benefits (one pass traversal) is moot, as it actually is a two-pass traversal (one being hidden in the call tree of the Lazy.force functions), and the code is of course much slower than the plain two-pass version. -- bluestorm On 2/26/08, Loup Vaillant wrote: > 2008/2/26, Damien Doligez : > > The restriction is documented in section 7.3 of the reference manual, > > and it's here to make recursive definitions work correctly under > > eager evaluation. > > OK, I got it. By the way, replacing "couple" by "couple ()" does the trick: > > # let loop f a = > let rec couple () = f (a, snd (couple ())) in > fst (couple ());; > val loop : ('a * 'b -> 'c * 'b) -> 'a -> 'c = > > Now, I have yet to figure out the purpose of this so called "fixpoint > operator" (and if the above will work at all :-). > > Thank you all, > Loup > > _______________________________________________ > 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 >