From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: weis Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id WAA24540 for caml-redistribution; Fri, 17 Dec 1999 22:51:14 +0100 (MET) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id MAA00356 for ; Thu, 16 Dec 1999 12:57:20 +0100 (MET) Received: from julie.univ-savoie.fr (univax.univ-savoie.fr [193.48.120.32]) by nez-perce.inria.fr (8.8.7/8.8.7) with ESMTP id MAA28685; Thu, 16 Dec 1999 12:57:17 +0100 (MET) Received: from julie.univ-savoie.fr (julie.univ-savoie.fr [193.48.120.39]) by julie.univ-savoie.fr (8.9.3/jtpda-5.3.1) with ESMTP id MAA89258 ; Thu, 16 Dec 1999 12:56:41 +0100 (CET) Date: Thu, 16 Dec 1999 12:56:41 +0100 (CET) From: Christophe Raffalli To: Judicael Courant cc: Daniel de Rauglaudre , Norman Ramsey , caml-list@inria.fr Subject: Re: A common use of try ... with In-Reply-To: <14424.39043.786900.267749@pc87.lri.fr> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: weis 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