代码:
connected edges = connect slist tslist edges
where tslist = tail(slist)
slist = sort (remdup (myflatten edges))
connect _ [] _ = True
connect (x:xs) slist edges = if (findpaths x slist edges) then (connect xs list edges) else False
where list = tail(slist)
findpaths _ [] _ = True
findpaths x (y:ys) edges = if (findpath x y edges edges []) then (findpaths x ys edges)
else False
findpath _ _ [] _ _ = False
findpath x y ((w,z):xs) edges nodes | ((x==w && y==z) || (x==z && y==w)) = True
line 57 | (x==w && not(member z nodes)) = (findpath z y edges edges nodes++[z] || findpath y z edges edges nodes++[z])
line 58 | (x==z && not(member w nodes)) = (findpath w y edges edges nodes++[w] || findpath y w edges edges nodes++[w])
| otherwise = findpath x y xs edges nodes
“少数”错误:
project2.hs:57:72:
Couldn't match expected type `[a0]' with actual type `Bool'
In the return type of a call of `findpath'
In the first argument of `(++)', namely
`findpath z y edges edges nodes'
In the first argument of `(||)', namely
`findpath z y edges edges nodes ++ [z]'
project2.hs:57:72:
Couldn't match expected type `Bool' with actual type `[a0]'
In the first argument of `(||)', namely
`findpath z y edges edges nodes ++ [z]'
In the expression:
(findpath z y edges edges nodes ++ [z]
|| findpath y z edges edges nodes ++ [z])
In an equation for `findpath':
findpath x y ((w, z) : xs) edges nodes
| ((x == w && y == z) || (x == z && y == w)) = True
| (x == w && not (member z nodes))
= (findpath z y edges edges nodes ++ [z]
|| findpath y z edges edges nodes ++ [z])
| (x == z && not (member w nodes))
= (findpath w y edges edges nodes ++ [w]
|| findpath y w edges edges nodes ++ [w])
| otherwise = findpath x y xs edges nodes
project2.hs:57:111:
Couldn't match expected type `[a0]' with actual type `Bool'
In the return type of a call of `findpath'
In the first argument of `(++)', namely
`findpath y z edges edges nodes'
In the second argument of `(||)', namely
`findpath y z edges edges nodes ++ [z]'
project2.hs:57:111:
Couldn't match expected type `Bool' with actual type `[a0]'
In the second argument of `(||)', namely
`findpath y z edges edges nodes ++ [z]'
In the expression:
(findpath z y edges edges nodes ++ [z]
|| findpath y z edges edges nodes ++ [z])
In an equation for `findpath':
findpath x y ((w, z) : xs) edges nodes
| ((x == w && y == z) || (x == z && y == w)) = True
| (x == w && not (member z nodes))
= (findpath z y edges edges nodes ++ [z]
|| findpath y z edges edges nodes ++ [z])
| (x == z && not (member w nodes))
= (findpath w y edges edges nodes ++ [w]
|| findpath y w edges edges nodes ++ [w])
| otherwise = findpath x y xs edges nodes
project2.hs:58:72:
Couldn't match expected type `[a0]' with actual type `Bool'
In the return type of a call of `findpath'
In the first argument of `(++)', namely
`findpath w y edges edges nodes'
In the first argument of `(||)', namely
`findpath w y edges edges nodes ++ [w]'
project2.hs:58:72:
Couldn't match expected type `Bool' with actual type `[a0]'
In the first argument of `(||)', namely
`findpath w y edges edges nodes ++ [w]'
In the expression:
(findpath w y edges edges nodes ++ [w]
|| findpath y w edges edges nodes ++ [w])
In an equation for `findpath':
findpath x y ((w, z) : xs) edges nodes
| ((x == w && y == z) || (x == z && y == w)) = True
| (x == w && not (member z nodes))
= (findpath z y edges edges nodes ++ [z]
|| findpath y z edges edges nodes ++ [z])
| (x == z && not (member w nodes))
= (findpath w y edges edges nodes ++ [w]
|| findpath y w edges edges nodes ++ [w])
| otherwise = findpath x y xs edges nodes
project2.hs:58:111:
Couldn't match expected type `[a0]' with actual type `Bool'
In the return type of a call of `findpath'
In the first argument of `(++)', namely
`findpath y w edges edges nodes'
In the second argument of `(||)', namely
`findpath y w edges edges nodes ++ [w]'
project2.hs:58:111:
Couldn't match expected type `Bool' with actual type `[a0]'
In the second argument of `(||)', namely
`findpath y w edges edges nodes ++ [w]'
In the expression:
(findpath w y edges edges nodes ++ [w]
|| findpath y w edges edges nodes ++ [w])
In an equation for `findpath':
findpath x y ((w, z) : xs) edges nodes
| ((x == w && y == z) || (x == z && y == w)) = True
| (x == w && not (member z nodes))
= (findpath z y edges edges nodes ++ [z]
|| findpath y z edges edges nodes ++ [z])
| (x == z && not (member w nodes))
= (findpath w y edges edges nodes ++ [w]
|| findpath y w edges edges nodes ++ [w])
| otherwise = findpath x y xs edges nodes
有人可以为了上帝的缘故向我解释这些f ***匹配是如何运作的吗?我做了一些更改,但我改变了正确的事情,无法找到问题的根源。我是haskell的新手,PL很奇怪,因为我至少认为,没有严格的功能格式化,匹配过程让我感到困惑。谢谢你。
答案 0 :(得分:3)
你需要围绕(节点++ [z])
另外,它将像这样计算
(findpath z y edges edges nodes)++[z]
函数应用程序总是比任何中缀操作符更强大