caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Christophe Raffalli <Christophe.Raffalli@univ-savoie.fr>
To: Judicael Courant <Judicael.Courant@lri.fr>
Cc: Daniel de Rauglaudre <daniel.de_rauglaudre@inria.fr>,
	Norman Ramsey <nr@eecs.harvard.edu>,
	caml-list@inria.fr
Subject: Re: A common use of try ... with
Date: Thu, 16 Dec 1999 12:56:41 +0100 (CET)	[thread overview]
Message-ID: <Pine.BSF.4.10.9912161250070.71578-100000@julie.univ-savoie.fr> (raw)
In-Reply-To: <14424.39043.786900.267749@pc87.lri.fr>



On Thu, 16 Dec 1999, Judicael Courant wrote:

> tryeval exp
> val x -> f x (* this case is evaluated only when exp evaluates to a value *)
> with
> (* possible exceptions *)
> | Exception1 -> ...
> | Exception2 y -> ...
> ...
> 
> which is IMHO more readable and general than the workaround you
> mentionned.
> 

You can do this:

try raise (Val exp) with
  Val x -> f x
| Exception1 -> ...
| Exception2 y -> ...   

this is quite readable and does exactly what you want.

Is this optimized by the compiler (there is no need to construct the (Val
x) exception? If it is the case, this is a reasonable syntax. 

The main pb is that the Val exception needs to be definied for each type
as polymorphic exceptions are not allowed. 

One could make Val a reserved word (and not an exception) and propose the
following syntax:

try exp with
  Val y -> f x
| ....

The Val y case being use when no exceptions are raised.

Christophe Raffalli





  parent reply	other threads:[~1999-12-17 21:51 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-12-14 19:53 my stupidity and non-tail calls Norman Ramsey
1999-12-15 10:04 ` Daniel de Rauglaudre
1999-12-16  7:45   ` A common use of try ... with Judicael Courant
1999-12-16 10:43     ` Daniel de Rauglaudre
1999-12-16 11:56     ` Christophe Raffalli [this message]
1999-12-15 16:39 ` my stupidity and non-tail calls David Brown
1999-12-16 11:40 A common use of try ... with Andrew Kennedy

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=Pine.BSF.4.10.9912161250070.71578-100000@julie.univ-savoie.fr \
    --to=christophe.raffalli@univ-savoie.fr \
    --cc=Judicael.Courant@lri.fr \
    --cc=caml-list@inria.fr \
    --cc=daniel.de_rauglaudre@inria.fr \
    --cc=nr@eecs.harvard.edu \
    /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).