Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
From: John Prevost <j.prevost@c...>
Subject: Re: [Caml-list] Has laziness changed type?
>>>>> "ab" == Alessandro Baretta <alex@baretta.com> 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 *)

or

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.

John.
-------------------
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