checkstring :: [String] -> Int -> [String]
checkstring p n = do z <- doesFileExist (p !! n)
if z
then p
else error $ "'" ++ (p !! n) ++ "' file path does not exist"
它通过查看“n”(因此如果n = 2,它将检查列表中的第二个字符串是否存在)来检查字符串中的元素。如果它确实存在,它将返回原始字符串列表,如果不存在,它将会出错。为什么它会这样做? :Haskell怪异返回
Couldn't match expected type `[t0]' with actual type `IO Bool'
In the return type of a call of `doesFileExist'
In a stmt of a 'do' expression: z <- doesFileExist (p !! n)
请参阅http://stackoverflow.com/questions/6904169/managing-the-io-monad上的答案和讨论 – MatrixFrog