为什么“所有â€ç»™æˆ‘这个“无法匹é…预期类型â€ï¼Ÿ

时间:2011-02-03 15:51:59

标签: haskell map matrix

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)

2 个答案:

答案 0 :(得分:4)

您将å称all绑定到整个列表,因此å‰å¥å‡½æ•°allä¸å†å¯è§ã€‚选择其他å称,或删除all@,然åŽä½¿ç”¨let (m, n) = (length xs + 1, ...)或类似内容。

相关:你为什么è¦è®¡ç®—length all?你ä¸è¦åœ¨ä»»ä½•åœ°æ–¹ä½¿ç”¨å®ƒã€‚

答案 1 :(得分:4)

原因是,您将符å·allé‡æ–°å®šä¹‰ä¸ºtçš„å‚数。因此,本地all会影å“全局all,并且您会收到此错误。作为解决方案,请å°è¯•ä¸ºæ‚¨çš„本地allæä¾›å¦ä¸€ä¸ªå称。