为什么“全部”?给我这个“无法匹配预期类型”?
m = [[1,0,0],[2,-3,0],[4,5]]
t all@(x:xs) = let (m, n) = (length all, length x) in all (==n) (map length all)
命令:
t m
给出:
Couldn't match expected type `(Int -> Bool) -> [Int] -> t'
against inferred type `[[a]]'
In the expression: all (== n) (map length all)
In the expression:
let (m, n) = (length all, length x) in all (== n) (map length all)
In the definition of `t':
t (all@(x : xs))
= let (m, n) = ... in all (== n) (map length all)
m = [[1,0,0],[2,-3,0],[4,5]]
t all@(x:xs) = let (m, n) = (length all, length x) in all (==n) (map length all)
The command:
t m
gives:
Couldn't match expected type `(Int -> Bool) -> [Int] -> t'
against inferred type `[[a]]'
In the expression: all (== n) (map length all)
In the expression:
let (m, n) = (length all, length x) in all (== n) (map length all)
In the definition of `t':
t (all@(x : xs))
= let (m, n) = ... in all (== n) (map length all)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
原因是,您将符号
all
重新定义为t
的参数。因此,本地all
遮蔽了全局all
并且您会收到此错误。作为解决方案,请尝试为本地all
指定另一个名称。The reason is, that you redefine the symbol
all
to the parameter oft
. Thus, the localall
shadows the globalall
and you get this error. As a solution, try to give your localall
another name.您将名称
all
绑定到整个列表,因此前奏函数all
不再可见。选择不同的名称,或者删除all@
并仅使用let (m, n) = (length xs + 1, ...)
或类似的名称。相关:为什么你要计算
length all
?你不在任何地方使用它。You bind the name
all
to the whole list, so the prelude functionall
is no longer visible. Choose a different name, or drop theall@
and just uselet (m, n) = (length xs + 1, ...)
or something similar.Relatedly: Why do you calculare
length all
at all? You don't use it anywhere.