From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id B3B33BB91 for ; Sun, 26 Dec 2004 16:25:18 +0100 (CET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id iBQFPIkJ027538 for ; Sun, 26 Dec 2004 16:25:18 +0100 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id QAA22259 for ; Sun, 26 Dec 2004 16:25:17 +0100 (MET) Received: from mail-eur.microsoft.com (mail-eur.microsoft.com [213.199.128.145]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id iBQFPHvu019819 for ; Sun, 26 Dec 2004 16:25:17 +0100 Received: from EUR-MSG-03.europe.corp.microsoft.com ([65.53.192.44]) by mail-eur.microsoft.com with Microsoft SMTPSVC(6.0.3790.211); Sun, 26 Dec 2004 15:25:16 +0000 X-MimeOLE: Produced By Microsoft Exchange V6.5.7226.0 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Subject: RE: [Caml-list] Checking for eof Date: Sun, 26 Dec 2004 15:25:05 -0000 Message-ID: <5DCA48FADB33FF4D8C32A164DF24F2B002374E6E@EUR-MSG-03.europe.corp.microsoft.com> Thread-Topic: [Caml-list] Checking for eof Thread-Index: AcTrTTos+18zBV4UTau3aEZUVhyyVQADXPfg From: "Don Syme" To: "Nicolas George" , "Caml mailing list" Cc: "Andrew Kennedy" , "Nick Benton" X-OriginalArrivalTime: 26 Dec 2004 15:25:16.0650 (UTC) FILETIME=[1A2884A0:01C4EB5F] X-Miltered: at nez-perce with ID 41CED7DE.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 41CED7DD.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 syme:01 dsyme:01 benton:01 syntax:01 sml:01 variants:01 ocaml:01 bindings:01 expr:01 bindings:01 rec:01 expr:01 syntax:01 iterated:01 X-Spam-Checker-Version: SpamAssassin 3.0.0 (2004-09-13) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.0 X-Spam-Level: Nick Benton and Andrew Kennedy have addressed this rather = under-appreciated deficiency in ML exceptions in their paper = "Exceptional Syntax" http://research.microsoft.com/~akenn/sml/ExceptionalSyntax.pdf The topic has also been raised here before = http://caml.inria.fr/archives/200407/msg00028.html=20 I think this is so sensible that it should be adopted in all variants of = ML.=20 An OCaml or F# version of their construct might be=20 "let try =20 in =20 with " Only the bindings are covered by the "try". e.g. let readfile chan =3D let rec loop rlst =3D let try line =3D input_line chan in loop (line :: rlst) with End_of_file -> List.rev rlst in loop [] (note: reduces 17 lines to 7) Another possibility might be=20 "let try =20 with in " or indeed you could support both of the above, leaving it up to the = programmer to choose where to place the ever-awkward handling code. = Unfortunately the syntax=20 "try let =20 in =20 with " is too ambiguous when iterated "let ... in" bindings are used. Don -----Original Message----- From: caml-list-admin@yquem.inria.fr = [mailto:caml-list-admin@yquem.inria.fr] On Behalf Of Nicolas George Sent: 26 December 2004 14:09 To: Caml mailing list Subject: Re: [Caml-list] Checking for eof Le sextidi 6 niv=F4se, an CCXIII, briand@aracnet.com a =E9crit=A0: > try > (input_line chan), false > with > | End_of_file -> "", true I would have written that try Some (input_line chan) with | End_of_file -> None but the idea is the same. I find it is an irritating limitation of OCaml syntax to have to pack and then unpack all local values in order to = uncatch exceptions. Something like try let line =3D input_line chan in untry loop (line :: rlst) with | End_of_file -> List.rev rlst This syntax is somewhat awkward: untry is neither a third member of the try...with structure, because it must be inside the flow of let...in declaration, nor a stand-alone statement, because it must not be allowed anywhere outside try...with. On the contrary, as far as I can see, the semantics is quite simple.