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=0.0 required=5.0 tests=none autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id 6994ABC69 for ; Wed, 3 Oct 2007 22:39:18 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAIeaA0fUGyodimdsb2JhbACONwEBAQgEBg8RBw X-IronPort-AV: E=Sophos;i="4.21,226,1188770400"; d="asc'?vcf'?scan'208";a="2342059" Received: from discorde.inria.fr ([192.93.2.38]) by mail2-smtp-roc.national.inria.fr with ESMTP; 03 Oct 2007 22:39:18 +0200 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l93KdG8M008433 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Wed, 3 Oct 2007 22:39:18 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAIeaA0fUGyodimdsb2JhbACONwEBAQgEBg8RBw X-IronPort-AV: E=Sophos;i="4.21,226,1188770400"; d="asc'?vcf'?scan'208";a="2342058" Received: from smtp3-g19.free.fr ([212.27.42.29]) by mail2-smtp-roc.national.inria.fr with ESMTP; 03 Oct 2007 22:39:17 +0200 Received: from smtp3-g19.free.fr (localhost.localdomain [127.0.0.1]) by smtp3-g19.free.fr (Postfix) with ESMTP id 9B49317B584; Wed, 3 Oct 2007 22:39:17 +0200 (CEST) Received: from Tocksi.local (unknown [82.253.223.12]) by smtp3-g19.free.fr (Postfix) with ESMTP id 29A4817B556; Wed, 3 Oct 2007 22:39:17 +0200 (CEST) Message-ID: <4703FDEF.7030900@univ-savoie.fr> Date: Wed, 03 Oct 2007 22:39:11 +0200 From: Christophe Raffalli User-Agent: Thunderbird 2.0.0.6 (Macintosh/20070728) MIME-Version: 1.0 To: kirillkh Cc: oleg@pobox.com, caml-list@inria.fr Subject: Re: [Caml-list] Re: Locally-polymorphic exceptions [was: folding over a file] References: <20071003083529.40DA2A99F@Adric.metnet.fnmoc.navy.mil> In-Reply-To: X-Enigmail-Version: 0.95.3 X-Enigmail-Version: 0.95.3 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enig4905ED5A28B7C30AB8B64393" X-Miltered: at discorde with ID 4703FDF4.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; christophe:01 raffalli:01 christophe:01 raffalli:01 univ-savoie:01 channel-:01 'a-:01 'b-:01 prev:01 val:01 prev:01 val:01 checker:01 channel-:01 'a-:01 X-Attachments: cset="utf-8" name="Christophe.Raffalli.vcf" name="Christophe.Raffalli.vcf" type="application/pgp-signature" name="signature.asc" name="signature.asc" This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig4905ED5A28B7C30AB8B64393 Content-Type: multipart/mixed; boundary="------------060509070009040004050702" This is a multi-part message in MIME format. --------------060509070009040004050702 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Hi, > > > exception Done of 'a > > > > let fold_file (file: in_channel) > > (read_func: in_channel->'a) > > (elem_func: 'a->'b->'b) > > (seed: 'b) =3D > > let rec loop prev_val =3D > > let input =3D > > try read_func file > > with End_of_file -> raise (Done prev_val) > > in > > let combined_val =3D elem_func input prev_val in > > loop combined_val > > in > > try loop seed with Done x -> x > In fact, if elem_func is known by the type checker not to raise any exception, then the exception need not to be garded by the Done constructor and the following program is safe: > let fold_file (file: in_channel) > (read_func: in_channel->'a) > (elem_func: 'a->'b->'b) > (seed: 'b) =3D > let rec loop prev_val =3D > let input =3D > try read_func file > with End_of_file -> raise prev_val > in > let combined_val =3D elem_func input prev_val in > loop combined_val > in > try loop seed with x -> x The only problem is that current type-checker do not treat exception well and reject this kind of code .... Just for fun (I could not resist), here is the pml code which is accepeted, but is useless since pml can not read file yet ;-) ---------- pml code --------- (* f,a,b are declared type variables, a =3D> b is the type of a function that raises no exception a -> b | e is the type of a function that raises only exception of type e a -> b is the type of a function with no indication about exceptions *= ) val (f,a,b) fold_file:(f =3D> (f -> a | [EOF[]]) =3D> (a=3D>b=3D>b) =3D> = b =3D> b) file read_func elem_func seed =3D let rec loop prev_val =3D let input =3D try read_func file with EOF[] -> raise prev_val in let combined_val =3D elem_func input prev_val in loop combined_val in try loop seed with x -> x ------------------------------- So the story is by saying (wrongly) that it is too heavy to anottate arrow types with exceptions, making the arrow type a ternary type construct, ML is missing a lot ... --=20 Christophe Raffalli Universite de Savoie Batiment Le Chablais, bureau 21 73376 Le Bourget-du-Lac Cedex tel: (33) 4 79 75 81 03 fax: (33) 4 79 75 87 42 mail: Christophe.Raffalli@univ-savoie.fr www: http://www.lama.univ-savoie.fr/~RAFFALLI --------------------------------------------- IMPORTANT: this mail is signed using PGP/MIME At least Enigmail/Mozilla, mutt or evolution=20 can check this signature. The public key is stored on www.keyserver.net --------------------------------------------- --------------060509070009040004050702 Content-Type: text/x-vcard; charset=utf-8; name="Christophe.Raffalli.vcf" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="Christophe.Raffalli.vcf" begin:vcard fn:Christophe Raffalli n:Raffalli;Christophe org:LAMA (UMR 5127) email;internet:christophe.raffalli@univ-savoie.fr title;quoted-printable:Ma=3DC3=3DAEtre de conf=3DC3=3DA9rences tel;work:+33 4 79 75 81 03 note:http://www.lama.univ-savoie.fr/~raffalli x-mozilla-html:TRUE version:2.1 end:vcard --------------060509070009040004050702-- --------------enig4905ED5A28B7C30AB8B64393 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (Darwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFHA/30i9jr/RgYAS4RAn2ZAJwK4UKWwGIns5S5KHPFaCLu+ZcSRgCgukh9 yEEncZQSugzvsFXxwgDS00Y= =H+QB -----END PGP SIGNATURE----- --------------enig4905ED5A28B7C30AB8B64393--