From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id RAA06008; Mon, 9 Sep 2002 17:17:20 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id RAA05451 for ; Mon, 9 Sep 2002 17:17:19 +0200 (MET DST) X-SPAM-Warning: Sending machine is listed in blackholes.five-ten-sg.com Received: from athlon.baretta.com (r-mi214-6a35.tin.it [62.211.4.35]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g89FHD903644 for ; Mon, 9 Sep 2002 17:17:15 +0200 (MET DST) Received: from baretta.com (localhost.localdomain [127.0.0.1]) by athlon.baretta.com (Postfix) with ESMTP id C9504273B9 for ; Mon, 9 Sep 2002 17:25:57 +0200 (CEST) Message-ID: <3D7CBD85.9090102@baretta.com> Date: Mon, 09 Sep 2002 17:25:57 +0200 From: Alessandro Baretta Organization: Baretta srl -- www.baretta.com User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.1) Gecko/20020826 X-Accept-Language: it, en MIME-Version: 1.0 To: Ocaml Subject: Re: [Caml-list] Has laziness changed type? (with a plea to Xavier...) References: <3D7A7C8B.9070901@baretta.com> <20020909162320.D1781@pauillac.inria.fr> <3D7CB742.5030908@baretta.com> <86admrus1c.fsf@laurelin.dementia.org> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk John Prevost wrote: >>>>>>"ab" == Alessandro Baretta writes: > > ab> This is not terribly useful when you have to match against > ab> only one lazy value, but the situation is different when you > ab> have a tuple of lazy values, and need to perform different > ab> actions depending on which subset of them computes a > ab> meaningful value. > > What's wrong with: > > try (* do something with *) (Lazy.force foo) with _ -> > try (* do something with *) (Lazy.force bar) with _ -> > try (* do something with *) (Lazy.force doh) with _ -> > (* fallback code *) This control structure happens to match perfectly the example I gave, but it is not as general. What If you want to to match conditions where two-out-of-three compute a value? What if the action you take also depends on the actual exception raised by the third? There are a host of examples where a patterm matching would be marvellously clear and concise, that you cannot easily convert to a number of nested try-with expressions. > or > > let lf x = try Some (Lazy.force x) with _ -> None > > match (lf a, lf b, lf c, lf d) with > ... Yes. This is basically my solution. It adds a little "background noise" in the tuple expression being matched. No big deal really. > or even > > type 'a result = Value of 'a | Exception of 'a > > let lf x = try Value (Lazy.force x) with e -> Exception e Ok. This is perfect. It just takes a couple more lines of code and one extra function application per tuple position. This is what I meant when I stated I had to rework my code a little. > > The change to the lazy datatype means you have to do a little extra > effort if you want to maintain this kind of information. But it's not > really a huge deal. > > John. Right, no big deal really. And if it's done for the sake of efficiency, then welcome Xavier's "purple magic". Might I just make a plea for the following library function in the Lazy module? type 'a forced = Value of 'a | Exception of exn let eval susp = try Value(force susp) with ex -> Exception(ex) Alex ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners