【发布时间】:2020-02-29 20:57:26
【问题描述】:
我正在尝试对列表进行递归迭代并检查所有值是否都等于 0, 我得到的错误是:
* Couldn't match expected type `[Integer]' with actual type `Bool'
* In the second argument of `(:)', namely `allZero s'
In the expression: 0 : allZero s
In an equation for `allZero': allZero (0 : s) = 0 : allZero s
我的代码是:
allZero :: [Int] -> Bool
allZero (0:_) = True
allZero (0:s) = 0 : allZero s
allZero (_:s) = False;
allZero _ = False
我不明白为什么我在allZero (0:s) = 0 : allZero s 的行中得到这个错误,我给它正确的参数,一个列表's'
【问题讨论】:
标签: list haskell recursion functional-programming