[Shootout-list] OCaml sum-file

Christophe TROESTLER del-con@tiscali.be
Sun, 27 Mar 2005 22:35:13 +0200 (CEST)


----Next_Part(Sun_Mar_27_22_35_13_2005_046)--
Content-Type: Text/Plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Hi,

I do not know what it the problem with the sum-file OCaml program --
it works here.  Here is an alternative version that is faster on my
machine (but rec fun v.s. loops performance varies from platform to
platform...)

ChriS


----Next_Part(Sun_Mar_27_22_35_13_2005_046)--
Content-Type: Text/Plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="sum-file.ml"

(* sum-file.ml
 *
 * The Great Computer Language Shootout
 * http://shootout.alioth.debian.org/
 *
 * Contributed by Troestler Christophe
 *)

let () =
  let sum = ref 0 in
  try while true do
    sum := !sum + int_of_string (input_line stdin)
  done with End_of_file -> print_int !sum; print_newline()

----Next_Part(Sun_Mar_27_22_35_13_2005_046)----