这里有几件事是错误的:
- 您将需要一个 else 子句。
True必须大写。
inputIndex必须始终采用两个参数(现在它没有,在最后一种情况下)。
我猜你想要这样的东西......
inputIndex :: [String] -> [String] -> IO ()
inputIndex listx input = if inputIndex' listx input
then putStrLn ("ok")
else putStrLn ("not ok")
where
inputIndex' :: [String] -> [String] -> Bool
inputIndex' listx input = and [x `elem` listx |x <- input]
(在这里,我通过附加一个撇号/撇号定义了一个名称几乎相同的新函数。通过在where子句中定义它,它只对外部inputIndex函数可见。如果你愿意,你可以将其称为辅助函数。我也可以选择一个完全不同的名字,但我没有创意。)
您还可以将其浓缩为以下内容(这也更笼统):
allPresent :: (Eq t) => [t] -> [t] -> IO ()
allPresent xs ys = putStrLn (if and [y `elem` xs | y <- ys] then "ok" else "not ok")