Guess what this prints, and after how long:
val fastTime = Time.fromSeconds 2
val slowTime = Time.fromSeconds 6
fun fib 0 = 1
| fib 1 = 1
| fib n = fib (n - 1) + fib (n - 2)
fun bigfib () = fib 10000000
fun slow () = TimeLimit.timeLimit slowTime bigfib ()
handle TimeLimit.TimeOut =>
let in
print "slow time out"
; ~1
end
val _ = TimeLimit.timeLimit fastTime slow ()
handle TimeLimit.TimeOut =>
let in
print "fast time out"
; ~2
end
The rather unintuitive answer is "slow time out" after 6 seconds.
What is going on here? I guess nesting of TimeLimits is dangerous.
Thursday, February 19, 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment