【发布时间】:2014-03-18 13:41:05
【问题描述】:
我在 haskell 中有以下代码,我得到了
- 无法将类型 [Int] 与 `Bool' 匹配
- 无法匹配类型
[[a0]] -> [a0]' with[Int]' 预期类型:[Int] -> [Int] 实际类型:[Int] -> [[a0]] -> [a0]
代码:
findlist:: [[Int]] -> [Int]
findlist (l1, l2, l3, l4, l5) = do 1)
let n = length l1
e1 <- [1..n]
e2 <- [1..n]
e3 <- [1..n]
e4 <- [1..n]
e5 <- [1..n]
let list1 = pick_list $ myperms e1 l1 --here
list2 = pick_list $ myperms e2 l2 --here
list3 = pick_list $ myperms e3 l3 --here
list4 = pick_list $ myperms e4 l4 --here
list5 = pick_list $ myperms e5 l5 --here
guard $ all (== list1) $ [list2, list3, list4, list5]
guard $ e1 `notElem` [e2, e3, e4, e5]
guard $ e2 `notElem` [e3, e4, e5]
guard $ e3 `notElem` [e4, e5]
guard $ e4 `notElem` [e5]
return concat list1 2)
类型签名:
pick_list:: [[Int]] -> [Int]
myperms:: Int -> [Int] -> [[Int]]
它有什么问题,我怎么知道什么时候会出现这样的错误?提前致谢。
【问题讨论】:
-
我没有收到您遇到的错误。如果我输入
myperms :: Int -> [Int] -> [[Int]];myperms = undefined和pick_list :: [[Int]] -> [Int];pick_list = undefined。此外,我怀疑您是否尝试编译此确切代码,因为findlist采用 5 元组,而不是列表,但您显然已经给它一个类型签名,表明它需要一个列表。这是我使用此代码得到的唯一编译错误。 -
现在可以了,但是速度很慢。我考虑过限制 e1、e2 等的范围,但我需要一个函数来删除给定列表的给定子列表。
-
在这种情况下,它就像 e2
标签: haskell