From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 330AABB81 for ; Wed, 8 Dec 2004 01:30:22 +0100 (CET) Received: from woodstock.1969.ws (64-215-156-42.eosinc.net [64.215.156.42]) by nez-perce.inria.fr (8.13.0/8.13.0) with SMTP id iB80UK1u025700 for ; Wed, 8 Dec 2004 01:30:21 +0100 Received: (qmail 952 invoked from network); 8 Dec 2004 00:13:12 -0000 Received: from karl.1969.ws (HELO ?10.3.2.15?) (10.3.2.15) by woodstock.1969.ws with SMTP; 8 Dec 2004 00:13:12 -0000 Message-ID: <41B64B05.902@1969.ws> Date: Tue, 07 Dec 2004 16:29:57 -0800 From: Karl Zilles Organization: 1969 Communications, Inc. User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Hal Daume III Cc: Caml Mailing List Subject: Re: [Caml-list] lazy application to Lazy.t References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Miltered: at nez-perce with ID 41B64B1C.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 lazy:01 lazy:01 wrote:01 val:01 val:01 int:01 int:01 unit:02 unit:02 let:03 let:03 suppose:05 incr:06 incr:06 X-Spam-Checker-Version: SpamAssassin 3.0.0 (2004-09-13) on yquem.inria.fr X-Spam-Status: No, score=0.1 required=5.0 tests=FORGED_RCVD_HELO autolearn=disabled version=3.0.0 X-Spam-Level: Hal Daume III wrote: > suppose I have > > val x : int ref Lazy.t > > and I want to 'incr' it, but want to keep it lazy. i.e., if i start with: > > let x = Lazy.lazy_from_fun (fun () -> ref 0) > > then i run my lazy_incr on it, I want: > > let y = Lazy.force x > > to return 1 > > but i only want 'incr' to be run when I Lazy.force x. is there a way to > accomplish this? Not the way you have it. Because x is itself not a reference, you can't change its value by calling a function on it. If instead you had val x : int Lazy.t ref, then it would be possible: open Lazy;; let x = ref (lazy (0));; val x : int lazy_t ref = {contents = } let lazy_incr r = let current = !r in r:=lazy ((force current) + 1);; val lazy_incr : int Lazy.t ref -> unit = lazy_incr x;; - : unit = () force !x;; - : int = 1