悄悄退出(无一例外)haskell

Exit quietly (without exception) haskell

我知道

exitWith ExitSuccess

退出程序,但输出

*** Exception: ExitSuccess

我想知道是否有办法退出而不在屏幕上输出任何内容?

在此处扩展以上评论(致 Reid、Bakuriu 和 Jeffrey)。您很有可能在 ghci 中执行以下程序:

import System.Exit

main :: IO ()
main = exitWith ExitSuccess

现在在终端中:

$ ghci
λ> :load crash.hs -- crash.hs is the filename
λ> main
*** Exception: ExitSuccess

请注意 ghcighc 是不同的。 ghci 用作 Haskell 的 REPL。上面的代码像下面这样编译和执行时不会产生任何消息:

$ ghc -o crash crash.hs 
$ ./crash

请注意,REPL 是通过名为 ghci 的程序调用的。要编译和生成可执行文件,您必须使用名为 ghc.

的可执行文件