caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: John Prevost <j.prevost@cs.cmu.edu>
To: Alessandro Baretta <alex@baretta.com>
Cc: Xavier Leroy <xavier.leroy@inria.fr>, Ocaml <caml-list@inria.fr>
Subject: Re: [Caml-list] Has laziness changed type?
Date: 09 Sep 2002 11:00:31 -0400 (62.536 UMT)	[thread overview]
Message-ID: <86admrus1c.fsf@laurelin.dementia.org> (raw)
In-Reply-To: <3D7CB742.5030908@baretta.com>

>>>>> "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


  reply	other threads:[~2002-09-09 15:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-09-07 22:24 Alessandro Baretta
2002-09-09 14:23 ` Xavier Leroy
2002-09-09 14:59   ` Alessandro Baretta
2002-09-09 15:00     ` John Prevost [this message]
2002-09-09 15:25       ` [Caml-list] Has laziness changed type? (with a plea to Xavier...) Alessandro Baretta

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=86admrus1c.fsf@laurelin.dementia.org \
    --to=j.prevost@cs.cmu.edu \
    --cc=alex@baretta.com \
    --cc=caml-list@inria.fr \
    --cc=xavier.leroy@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).