Browse thread
Today's inflamatory opinion: exceptions are bad
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: | 2006-12-11 (23:38) |
From: | Olivier Andrieu <oandrieu@n...> |
Subject: | Re: [Caml-list] Today's inflamatory opinion: exceptions are bad |
Chris King [Saturday 9 December 2006] : > > On 12/9/06, Brian Hurt <bhurt@spnz.org> 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