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 QAA04503; Mon, 9 Sep 2002 16:50:33 +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 QAA04550 for ; Mon, 9 Sep 2002 16:50:32 +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 g89EoU902768; Mon, 9 Sep 2002 16:50:30 +0200 (MET DST) Received: from baretta.com (localhost.localdomain [127.0.0.1]) by athlon.baretta.com (Postfix) with ESMTP id C2D00273B9; Mon, 9 Sep 2002 16:59:14 +0200 (CEST) Message-ID: <3D7CB742.5030908@baretta.com> Date: Mon, 09 Sep 2002 16:59:14 +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: Xavier Leroy Cc: Ocaml Subject: Re: [Caml-list] Has laziness changed type? References: <3D7A7C8B.9070901@baretta.com> <20020909162320.D1781@pauillac.inria.fr> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Xavier Leroy wrote: > > An abstract type. You don't want to know :-) More seriously: in > 3.06, the compiler and runtime system represent lazy values more > efficiently; in particular, the "Value of" indirections present in > 3.04 are now shortened by the GC whenever possible. As a consequence, > the representation of lazy values no longer matches that of a Caml datatype. Cool! >>Can I apply pattern-matching on it? > > > No. The general "contract" of a lazy value is that you should never > have to distinguish whether it's been evaluated already or not. Just > perform Lazy.force on the lazy value and match on the result. > > - Xavier Leroy This is a pity, in a way, but not really a big problem. I often need to check whether a given lazy value corresponds computes a meaningful value or raises an exception. To do this I had code like the following let foo = lazy ( bar () ) let _ = try ignore (Lazy.force foo) with _ -> () in match foo with Value(x) -> ... Exception(x) -> ... This is not terribly useful when you have to match against only one lazy value, but the situation is different when you have a tuple of lazy values, and need to perform different actions depending on which subset of them computes a meaningful value. I solved my problem by reworking the code. It was not too much effort after all, but my code lost its former elegance: match foo, bar, doh with | Value(foo), _, _ -> ... | _, Value(bar), _ -> ... | _, _, Value(doh) -> ... 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