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 mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 434C2BC69 for ; Fri, 19 Oct 2007 15:49:54 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAKpSGEdA6aLsmGdsb2JhbACOVwIBAQcCCBEW X-IronPort-AV: E=Sophos;i="4.21,301,1188770400"; d="scan'208";a="18350929" Received: from nz-out-0506.google.com ([64.233.162.236]) by mail4-smtp-sop.national.inria.fr with ESMTP; 19 Oct 2007 15:49:53 +0200 Received: by nz-out-0506.google.com with SMTP id x7so46342nzc for ; Fri, 19 Oct 2007 06:49:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=beta; 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=VN3LCN78h8zah5D4g+jU3HS3pqfa/BYZnes/6DQdAsQ=; b=VZXuUTMUBFeDYuUfTHVhUGBBGTg0Q80jsD/nmLNf/xz8SlC0EgkQe7N+OxqzJy7SmVkeOQq1sqfhyUepR7AB+91DxDIni3wonSLRwH4TW2kKcTnaLc3E8dEMXe6X4Obay7+g1H81emW0u1krOH8MBn12PT7Np6sEh5R+1m1HtEk= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=g4h/Zpc+FiPgs9CHGz6I/175MHHAI8i9gU4kARt9SXXBOvoSk3ONSSXMHbUfWcluLKIz5e6zMX+PDZvAwAtXcDdeG0bECx9OIOlN1sSOxXgxfoJeAkkzoYoYJzWEUtGjs0coFqn5KCPW1d2oc3MtcqgPZGU9PD0TJ2V5qjSltJA= Received: by 10.115.47.1 with SMTP id z1mr2057081waj.1192801788069; Fri, 19 Oct 2007 06:49:48 -0700 (PDT) Received: by 10.114.13.16 with HTTP; Fri, 19 Oct 2007 06:49:47 -0700 (PDT) Message-ID: <6f9f8f4a0710190649x2ad33e26h3b1421a63df21780@mail.gmail.com> Date: Fri, 19 Oct 2007 15:49:47 +0200 From: "Loup Vaillant" To: "Brian Hurt" Subject: Re: [Caml-list] Help me find this pdf Cc: "Jon Harrop" , caml-list@yquem.inria.fr In-Reply-To: <4718AA76.3010103@janestcapital.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <200710181457.58077.jon@ffconsultancy.com> <47176C28.1090509@janestcapital.com> <200710181818.31430.jon@ffconsultancy.com> <4718AA76.3010103@janestcapital.com> X-Spam: no; 0.00; compiler:01 node:01 node:01 integers:01 syntactic:01 syntactic:01 caml-list:01 unsafe:01 lazy:02 lazy:02 off-topic:02 match:02 match:02 figuring:02 element:03 2007/10/19, Brian Hurt : > The only thing missing is some syntactic sugar to make the above pattern > matching nicer- computationally, the same values will need to be forced. If > you're arguing in favor of the syntactic sugar, I'm sympathetic. If you're > arguing that the compiler could somehow avoid forcing the same > values, I don't see how. (Disclaimer: I suspect I'm a bit off-topic) 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 [...] ;; Well, I think this is overdoing laziness: more often than not, the rest of a lazy list depends on the value of it's head (e.g. the list of all integers, of a Fibonacci list). In such cases, doubling the cost of laziness is worth nothing. Regards, Loup Vaillant