止められる fib その2

killThread という関数を使えば、別に Maybe とかで頑張らなくてもいいね。

main = do putStrLn "Enter number: "
          n <- getLine
          id <- forkIO $ fib (read n)
          putStrLn "Press any key to stop calculation."
          getChar
          killThread id
          putStrLn "Now thread stops."
          getChar
          return ()
fib n = print $ fib' n
fib' n | n < 1 = 1
       | otherwise = fib' (n-1) + fib' (n-2)