From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: * X-Spam-Status: No, score=1.0 required=5.0 tests=AWL,SPF_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 83551BC0C for ; Sat, 23 Dec 2006 05:23:50 +0100 (CET) Received: from wx-out-0506.google.com (wx-out-0506.google.com [66.249.82.238]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id kBN4NnDZ019379 for ; Sat, 23 Dec 2006 05:23:49 +0100 Received: by wx-out-0506.google.com with SMTP id i31so2911295wxd for ; Fri, 22 Dec 2006 20:23:48 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=fd0vxRuOMc0A0ef2TLe33nTpSSzDONhUmsCT4cuuZBSAOtNs9wZ8M5Etmcg0mIhwhGWGfMbaVAqOQiDkHU8m2gI+a+C1telQiyjcJINYPzXb2tqS41STZ9/hsZGrDF03rDokUSk7Fpacvy89gYHa/FLWqI92u/ippL7LK0h+i7U= Received: by 10.90.118.12 with SMTP id q12mr9686311agc.1166847828808; Fri, 22 Dec 2006 20:23:48 -0800 (PST) Received: by 10.90.115.1 with HTTP; Fri, 22 Dec 2006 20:23:43 -0800 (PST) Message-ID: <875c7e070612222023j425f7a47yb83da6725196afc7@mail.gmail.com> Date: Fri, 22 Dec 2006 23:23:43 -0500 From: "Chris King" To: "Bruno De Fraine" Subject: Re: Ocaml checked exceptions Cc: caml-list@inria.fr In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <875c7e070612091935q2388092dr51538ff444d0e3a6@mail.gmail.com> X-j-chkmail-Score: MSGID : 458CAF55.000 on concorde : j-chkmail score : X : 0/20 1 0.000 -> 1 X-Miltered: at concorde with ID 458CAF55.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; ocaml:01 variants:01 stack:01 syntax:01 val:01 iter:01 val:01 iter:01 ocamlexc:01 ocamlexc:01 variants:01 abbreviation:01 enumerating:01 vub:98 polymorphic:01 On 12/18/06, Bruno De Fraine wrote: > I think support in the type system for exceptions would look a lot > like that for polymorphic variants. You can do some of the things you > suggest with them, but there are some important shortcomings (other > than the obvious issue that an exception aborts the normal control > flow and moves up the stack until it is handled). Agreed, I wonder if a proof-of-concept syntax extension could be written to take advantage of this similarity? (Of course its performance would be abysmal! but it would be a good way to try such a system in a larger project.) > > val List.iter: ('a -> unit raises 'b) -> 'a list -> unit raises 'b > > val iter : ('a -> ([> `Val of unit ] as 'b)) -> 'a list -> 'b = > > This is a bit different from how you describe the type, but in > principle I can agree: "iter will have the same return type as the > argument function; this should include a normal unit value". Yes, this type seems to fit well. > > val catch_failures: ('a -> 'b raises [Failure of string | 'c]) -> 'a > > -> 'b raises 'c > > val catch_failures : > ('a -> ([> `Failure of string | `Val of 'c ] as 'b)) -> 'a -> 'c - > > 'b = > > > It is problematic that the final return type will be the same as that > from the argument. I.e. the exception that we catch is not removed: OcamlExc (http://caml.inria.fr/pub/old_caml_site/ocamlexc/ocamlexc.htm) seems to make some headway into this problem by doing flow analysis... whether it can handle this specific case I'm not sure but I wouldn't be surprised. I also know of no way to express this using variants. Although we could say something like val catch_failures : ('a -> ([> `Failure of string | `Val of 'c | everything_else ] as 'b)) -> 'a -> 'c -> everything_else and replace the default match case with a case matching [> everything_else], there's currently no way (that I know of) to create the "everything_else" type abbreviation, short of enumerating all known exceptions manually. - Chris