我正在尝试在Haskell中创建一个小程序。我需要做的是检查Haskell解释器是否已成功执行bash命令。让我们说“伪代码”:
$import System
$if( system "ls" ) has been succesfully run
$then doStuff
你会如何在Haskell中编写这段代码?
答案 0 :(得分:7)
你可以这样做:
import System
main = do
result <- system "ls"
case result of
ExitSuccess ->
putStrLn "Ran successfully"
ExitFailure code ->
putStrLn $ "Failed with exit code " ++ show code