我正在研究一些Haskell(请原谅新手错误) -
这个例程出错了.我对do&< - 语法的理解是它们从monad中提取非Monad类型.所以理解是有缺陷的:这里的正确理解是什么?
exister :: String -> Bool
exister path = do
fileexist <- doesFileExist path
direxist <- doesDirectoryExist path
return fileexist || direxist
Run Code Online (Sandbox Code Playgroud)
错误
ghc -o joiner joiner.hs
joiner.hs:53:2:
Couldn't match expected type `Bool' against inferred type `m Bool'
In the first argument of `(||)', namely `return fileexist'
In the expression: return fileexist || direxist
In the expression:
do { fileexist <- doesFileExist path;
direxist <- doesDirectoryExist path;
return fileexist || direxist }
Run Code Online (Sandbox Code Playgroud) haskell ×1