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 WAA14022; Thu, 13 Mar 2003 22:43:13 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id WAA13377 for ; Thu, 13 Mar 2003 22:43:12 +0100 (MET) Received: from epexch01.qlogic.org ([63.170.40.3]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h2DLh9X26739 for ; Thu, 13 Mar 2003 22:43:10 +0100 (MET) Received: from epmailtmp.qlogic.org ([10.20.33.254]) by epexch01.qlogic.org with Microsoft SMTPSVC(5.0.2195.5329); Thu, 13 Mar 2003 15:44:36 -0600 Received: from [10.20.33.146] ([10.20.33.146]) by epmailtmp.qlogic.org with Microsoft SMTPSVC(5.0.2195.4905); Thu, 13 Mar 2003 15:44:35 -0600 Date: Thu, 13 Mar 2003 15:53:40 -0600 (CST) From: Brian Hurt X-X-Sender: Reply-To: Brian Hurt To: Karl Zilles cc: "Daniel M. Albro" , Subject: Re: [Caml-list] OCaml popularity In-Reply-To: <3E70F854.7020705@1969.ws> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-OriginalArrivalTime: 13 Mar 2003 21:44:35.0885 (UTC) FILETIME=[BD8FADD0:01C2E9A9] X-Spam: no; 0.00; qlogic:01 caml-list:01 fleshed:01 recursion:01 foo:01 unroll:01 ocaml:01 writting:01 rec:01 optimizer:02 exception:02 rewritten:02 stack:02 unit:03 wrote:03 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Thu, 13 Mar 2003, Karl Zilles wrote: > Daniel M. Albro wrote: > > imperative side of the language will get fleshed out a bit with some > > expanded loop features like break statements, > > You can always implement a break statement as an exception: > > exception Break;; > > try for i = 1 to 10 do > if i == 5 then raise Break > done with Break -> ();; > > As an exception, you could (if you wanted) include special case handling > for the break, or create a more aptly named exception and pass through > data. How efficient is this vr.s rewritting the loop as a tail recursion? I.e.: let rec loop idx = if (idx == 10) then () (* exit the loop *) else if special_case(idx) then () (* early exit of the loop *) else begin foo(idx); loop (idx + 1) end in loop 1 Naturally, instead of returning unit, the function can return whatever. All for loops can be rewritten as while loops, and all while loops can be rewritten as tail recursive functions. What I'm worried about is the costs of throwing an exception. This isn't C++ (where throwing an exception needs to unroll the stack, calling all the correct destructors, and can therefor be quite expensive), but that doesn't mean exceptions are 'cheap'. Exceptions, by definition, are exceptional. Were I writting the optimizer, I'd freely assume that any code path that ends in throwing an exception is not a critical path and can be slow. Brian ------------------- 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