From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id TAA00186; Thu, 8 Jul 2004 19:23:56 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f 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 TAA00831 for ; Thu, 8 Jul 2004 19:23:55 +0200 (MET DST) Received: from annexia.force9.co.uk (annexia.force9.co.uk [212.56.101.183]) by concorde.inria.fr (8.12.10/8.12.10) with ESMTP id i68HNsSH024712 for ; Thu, 8 Jul 2004 19:23:55 +0200 Received: from rich by annexia.force9.co.uk with local (Exim 3.36 #1 (Debian)) id 1Bicck-0004Yc-00 for ; Thu, 08 Jul 2004 18:23:54 +0100 Date: Thu, 8 Jul 2004 18:23:54 +0100 Cc: caml-list Subject: Re: Tail calls (Was Re: [Caml-list] Does Caml have slow arithmetics ?) Message-ID: <20040708172354.GA17402@redhat.com> References: <20040707091308.GA26172@bourg.inria.fr> <20040707145803.GB27498@yquem.inria.fr> <1089227778.29648.81.camel@pelican.wigram> <20040708034455.GB29942@davidb.org> <40ED190E.3080005@ps.uni-sb.de> <20040708140408.GA2386@davidb.org> <20040708163653.A1260@beaune.inria.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.5.1+cvs20040105i From: Richard Jones X-Miltered: at concorde with ID 40ED832A.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 arithmetics:01 ocamlopt:01 ocamlopt:01 extlib:01 iterating:01 type-safe:01 ltd:98 compiler:01 caml:01 caml:01 rec:01 namely:02 optimized:02 exception:02 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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 = try let line = input_line chan in line :: input_all_lines chan with 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. Rich. -- Richard Jones. http://www.annexia.org/ http://www.j-london.com/ Merjis Ltd. http://www.merjis.com/ - improving website return on investment MOD_CAML lets you run type-safe Objective CAML programs inside the Apache webserver. http://www.merjis.com/developers/mod_caml/ ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners