Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] Has laziness changed type?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2002-09-09 (15:00)
From: John Prevost <j.prevost@c...>
Subject: Re: [Caml-list] Has laziness changed type?
>>>>> "ab" == Alessandro Baretta <> writes:

    ab> This is a pity, in a way, but not really a big problem. I
    ab> often need to check whether a given lazy value corresponds
    ab> computes a meaningful value or raises an exception. To do this
    ab> I had code like the following


    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 *)


let lf x = try Some (Lazy.force x) with _ -> None

match (lf a, lf b, lf c, lf d) with

or even

type 'a result = Value of 'a | Exception of 'a

let lf x = try Value (Lazy.force x) with e -> Exception e


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.

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: