投稿テスト

とりあえず Fibonacci 数列を表示する Standard ML のプログラムでも書いておきます.

structure Fibonacci =
  struct
    local
      fun natsUpTo n = if n < 0 then NONE
                                else SOME (List.tabulate (n + 1, fn m => m))
    in
      fun fib n = 
        let
          fun fib' x _ 0 = x
            | fib' x y m = fib' y (x + y) (m - 1)
        in
          if n < 0 then NONE
                   else SOME (fib' 0 1 n)
        end
      fun printFib n =
        case fib n of
          SOME m => print ("fib_" ^ Int.toString n ^ " = " ^ Int.toString m ^ "\n")
        | NONE   => print "Too Small!!\n"
      fun printFibs n = app printFib ((valOf o natsUpTo) n)
                        handle Option   => print "Too Small!!\n"
                             | Overflow => print "Too Big!!\n"                       
    end
  end

fun readInt () = TextIO.scanStream (Int.scan StringCvt.DEC) TextIO.stdIn
val _ = case readInt () of SOME n => Fibonacci.printFibs n
                         | NONE   => print "Non-integer Value!!\n"