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 concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id D68BABC0A for ; Tue, 12 Dec 2006 00:38:40 +0100 (CET) Received: from kraid.nerim.net (smtp-101-monday.nerim.net [62.4.16.101]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id kBBNcepP025666 for ; Tue, 12 Dec 2006 00:38:40 +0100 Received: from karryall.dnsalias.org (karryall.dnsalias.org [213.41.240.180]) by kraid.nerim.net (Postfix) with ESMTP id AB69841086; Tue, 12 Dec 2006 00:38:38 +0100 (CET) Received: by karryall.dnsalias.org (Postfix, from userid 500) id EB53F300BCA; Tue, 12 Dec 2006 00:38:39 +0100 (CET) From: Olivier Andrieu MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <17789.60415.834724.854932@karryall.dnsalias.org> Date: Tue, 12 Dec 2006 00:38:39 +0100 To: "Chris King" Cc: caml-list Subject: Re: [Caml-list] Today's inflamatory opinion: exceptions are bad In-Reply-To: <875c7e070612091935q2388092dr51538ff444d0e3a6@mail.gmail.com> References: <875c7e070612091935q2388092dr51538ff444d0e3a6@mail.gmail.com> X-Mailer: VM 7.19 under Emacs 21.4.1 X-Miltered: at concorde with ID 457DEC00.001 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; andrieu:01 oandrieu:01 recursion:01 recursive:01 syntax:01 syntax:01 val:01 wrote:01 rec:01 rec:01 exception:01 exception:01 caml-list:01 exceptions:01 tail:01 Chris King [Saturday 9 December 2006] : > > On 12/9/06, Brian Hurt wrote: > > The second reason is that match ... with doesn't break tail recursion, > > while try ... with does. This code is not tail recursive: > > > > let rec echo_file channel = > > try > > begin > > let line = input_line channel in > > print_string (line ^ "\n"); > > echo_file channel > > end > > with > > | End_of_file -> () > > ;; > > I'm a big fan of Martin Jambon's "let try" syntax extension [1]. With > it the above construct can be written as: > > let rec echo_file channel = > let try line = input_line channel in > print_string (line ^ "\n"); > echo_file channel > with End_of_file -> () > > and would be tail-recursive. More often than not this is how I want > to write my exception handlers. I have a syntax extension with a somehow similar syntax, this example would written like that: ,---- | let rec echo_file channel = | catch input_line channel with | | exception End_of_file -> | () | | val line -> | print_string (line ^ "\n") ; | echo_file channel `---- the tail-recursion is a bit more apparent this way. -- Olivier