(* -*- mode: sml -*-
 * $Id: sumcol.smlnj,v 1.3 2001/07/09 00:25:28 doug Exp $
 * http://www.bagley.org/~doug/shootout/
 *)

structure Test : sig
    val main : (string * string list) -> OS.Process.status
end = struct

fun sumlines sum =
  if TextIO.endOfStream TextIO.stdIn
  then (print (Int.toString sum); print "\n")
  else case (Int.fromString (TextIO.inputLine TextIO.stdIn)) of
      NONE => sumlines sum
    | SOME i => sumlines (sum + i);

fun main(name, args) = (sumlines 0; OS.Process.success);

end

val _ = SMLofNJ.exportFn("sumcol", Test.main);