English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
my stupidity and non-tail calls
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 1999-12-17 (21:51)
From: Christophe Raffalli <Christophe.Raffalli@u...>
Subject: Re: A common use of try ... with

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