(* -*- mode: sml -*-
 * $Id: fibo.smlnj,v 1.5 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 fib 0 = 1
  | fib 1 = 1
  | fib n = fib (n-2) + fib (n-1);

fun atoi s = case Int.fromString s of SOME num => num | NONE => 0;

fun main(name, args) = 
  let
    val arg = hd(args @ ["1"]);
    val num = atoi arg;
    val fib = fib num;
    val result = Int.toString fib;
  in
      print result; print "\n";
      OS.Process.success
  end
end

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