18
我尝试以下方法:如何在Haskell中编写Ctrl-C处理程序?
import System.Exit
import System.Posix.Signals
import Control.Concurrent (threadDelay)
main :: IO()
main = do
installHandler keyboardSignal (Catch (do exitSuccess)) Nothing
threadDelay (1000000000)
但它只输出:
^CTest.hs: ExitSuccess
上Ctrl-C
,而不是退出。我应该如何正确地做到这一点?
线程'threadDelay(10000000)'做了什么? – Langston
['threadDelay'](http://hackage.haskell.org/package/base-4.8.1.0/docs/Control-Concurrent.html#v:threadDelay)“暂停当前线程达给定的微秒数”,类似于C中的'usleep'。在这里,我们暂停执行,唯一的目的是给用户足够的时间按下Ctrl-C。 –