Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] Does Caml have slow arithmetics ?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-07-08 (17:23)
From: Richard Jones <rich@a...>
Subject: Re: Tail calls (Was Re: [Caml-list] Does Caml have slow arithmetics ?)
This discussion of tail calls is very interesting.

I understand what Xavier is saying about ocamlopt not optimizing badly
written code.  Despite this, I have to say that ocamlopt does a
fantastic job!

However, I think there is one bit of badly written code where it would
be nice if the compiler could do a little bit more optimization,
namely functions such as:

let rec input_all_lines chan =
    let line = input_line chan in
    line :: input_all_lines chan
      End_of_file -> []

The reason is that (as discussed previously, so please don't repost)
the tail-recursive version of this sort of code is quite a bit more
complicated, and therefore quite a bit harder to remember.

Note that the specific input_all_lines function should be in a library
- it is in ExtLib, I think.  However I use that code /pattern/ quite
frequently, particularly when iterating over something which can throw
a Not_found or End_of_file exception and building a structure from the
result.  So I need to remember the optimized version of the pattern,
which my poor brain can't do.


Richard Jones.
Merjis Ltd. - improving website return on investment
MOD_CAML lets you run type-safe Objective CAML programs inside the Apache

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: