【发布时间】:2011-10-17 18:21:10
【问题描述】:
我正在学习一些 Haskell(请原谅新手错误)-
此例程出错。我对 do &
exister :: String -> Bool
exister path = do
fileexist <- doesFileExist path
direxist <- doesDirectoryExist path
return fileexist || direxist
错误
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 }
【问题讨论】:
-
从您下面的评论来看,您可能想查看这个问题及其答案:stackoverflow.com/questions/6628748/…(我们确实需要一个适当的常见问题解答)
-
我认为指出 Haskell 的
return与大多数语言中的“return”不太相似,这可能会有所帮助。如果您想要一个接受数字 n 并“返回”n+1 的函数,请编写f n = n + 1,而不是f n = return n+1。
标签: haskell