Date: Thu, 16 Dec 1999 12:56:41 +0100 (CET)
From: Christophe Raffalli <Christophe.Raffalli@univ-savoie.fr>
To: Judicael Courant <Judicael.Courant@lri.fr>
Subject: Re: A common use of try ... with
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
This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:29 MET