From: Brian Candler Date: 2003-08-26T01:35:56+09:00 Subject: Re: Rite/Ruby2.0 & Ruby vs OCaml On Tue, Aug 26, 2003 at 12:40:45AM +0900, mark wrote: > Unless I'm mistaken n + sum(n-1) isn't a tail call since it has to add n to > the result of sum(n-1) which prevents it from optimizing the call. > > The following code runs without any errors, though it prints the wrong answer > (probably due to overflow) > > let rec sum n total = > if n < 1 then total else sum (n-1) (total + n);; > > print_int(sum 1000000 0);; Ah, thank you, and sorry for exposing my ignorance! I was actually just trying to get some timings out. It seems ocaml is astoundingly fast for that test: 0.51s uncompiled, 0.37s compiled with ocamlc, versus 11.6s for the Ruby equivalent: def sum(n) total = 0 n.times { |x| total += x } total end puts sum(1000000) OTOH, the Ruby version gives the right answer :-) Cheers, Brian.