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_FAIL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr 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 9158BBC69 for ; Fri, 19 Oct 2007 16:38:58 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAOtdGEfAXQImh2dsb2JhbACOVwIBCAop X-IronPort-AV: E=Sophos;i="4.21,301,1188770400"; d="scan'208";a="3352839" Received: from discorde.inria.fr ([192.93.2.38]) by mail1-smtp-roc.national.inria.fr with ESMTP; 19 Oct 2007 16:38:58 +0200 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l9JEctLF007841 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Fri, 19 Oct 2007 16:38:58 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAOtdGEdQW+UCh2dsb2JhbACOVwIBCAop X-IronPort-AV: E=Sophos;i="4.21,301,1188770400"; d="scan'208";a="3352835" Received: from main.gmane.org (HELO ciao.gmane.org) ([80.91.229.2]) by mail1-smtp-roc.national.inria.fr with ESMTP; 19 Oct 2007 16:38:55 +0200 Received: from list by ciao.gmane.org with local (Exim 4.43) id 1Iit02-0002Q5-7V for caml-list@inria.fr; Fri, 19 Oct 2007 14:38:54 +0000 Received: from ivr94-8-88-162-26-239.fbx.proxad.net ([88.162.26.239]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 19 Oct 2007 14:38:54 +0000 Received: from li by ivr94-8-88-162-26-239.fbx.proxad.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 19 Oct 2007 14:38:54 +0000 X-Injected-Via-Gmane: http://gmane.org/ To: caml-list@inria.fr From: Zheng Li Subject: Re: Help me find this pdf Date: Fri, 19 Oct 2007 16:41:02 +0200 Message-ID: <87myuf2mm9.fsf@pps.jussieu.fr> References: <200710181457.58077.jon@ffconsultancy.com> <47176C28.1090509@janestcapital.com> <200710181818.31430.jon@ffconsultancy.com> <4718AA76.3010103@janestcapital.com> <6f9f8f4a0710190649x2ad33e26h3b1421a63df21780@mail.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: ivr94-8-88-162-26-239.fbx.proxad.net User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/23.0.50 (gnu/linux) Cancel-Lock: sha1:JoiwgfnZxGPflcwrqkymPV0mEP8= Sender: news X-Miltered: at discorde with ID 4718C17F.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; pred:01 parser:01 pred:01 combinator:01 node:01 node:01 rec:01 pps:01 pps:01 unsafe:01 jussieu:01 jussieu:01 int:01 writes:01 lazy:02 Just for fun :> ---- # let rec f ?(pred=[]) s = let conv = function [] -> [<>] | l -> [<'Some l>] in [< match s with parser | [<'Some x>] -> f ~pred:(pred@x) s | [<'h>] -> [] | [<>] -> [] >];; # open Sdflow;; # of_list [Some[1]; Some[2; 3]; None; Some[4; 5]] |> f |> to_list;; - : int list option list = [Some [1; 2; 3]; None; Some [4; 5]] ---- Note that any first element's evaluation is also lazy. The [f] above is defined with plain Stream, but you can archive the same with SDFlow's high-order combinator here such as map, map_fold etc. "Loup Vaillant" writes: > If we really want to, we can delay the evaluation at all costs, by > delaying even the car of the Cons cells > > type 'a node_t = > | Empty > | Cons of 'a Lazy.t * 'a lazylist > and 'a lazylist = 'a node_t Lazy.t > ;; > > For instance, when figuring out if the list is empty or not, the first > element isn't forced. You can even force the second element of the > list without forcing the first: > > match Lazy.force zlst with > | Cons(_, tl) -> > match Lazy.force tl with > | Cons(hd, _) -> > let head = Lazy.force hd in > [...] > ;; > > Or, assuming I can get away with unsafe code: > > let hd zlst = match Lazy.force zlst with > | Cons(h, _) = h > ;; > let tl zlst = match Lazy.force zlst with > | Cons(_, t) = t > ;; > > (* and finally *) > match Lazy.force hd (tl zlst) > with [...] > ;; -- Zheng Li http://www.pps.jussieu.fr/~li