我经常发现自己编写如下代码:
import System.Directory (doesFileExist)
import Control.Monad (unless)
example = do
fileExists <- doesFileExist "wombat.txt"
unless fileExists $ putStrLn "Guess I should create the file, huh?"
也许更好的方法是:
example2 =
doesFileExist "wombat.txt" >>=
(\b -> unless b $ putStrLn "Guess I should create the file, huh?")
这里最好的方法是什么?