Reading material

Pages 135-141 and 164-165.

Additional material

exception Factorial

local
    fun fact 0 = 1
      | fact n = n * fact (n-1)
in
    fun checked_fact n =
        if n >= 0 then
            fact n
        else
            raise Factorial
end 

fun driver () =
    let
        val input = read_integer ()
        val result = makestring (checked_fact input)
    in
        print result
    end
    handle Factorial => print "Invalid input.\n"