我试过这个:
tWLength (Node v l r) u | v == u = 0
| v < u = 1 + (tWLength l)
| v > u = 1 + (tWLength r)
然而它返回(在WinGHCi中):
experiments\treetest.hs:170:1: error:
• Occurs check: cannot construct the infinite type: a1 ~ a -> a1
Expected type: Tree a -> a1
Actual type: Tree a -> a -> a1
• Relevant bindings include
tWLength :: Tree a -> a1 (bound at experiments\treetest.hs:170:1)
|
170 | tWLength (Node v l r) u | v == u = 0
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^...
树定义为:
data Tree a = NullTree | Node a (Tree a) (Tree a) deriving (Show, Read, Eq, Ord)
答案 0 :(得分:2)
我现在找到了原因。我在
中只用一个参数调用tWLength
tWLength (Node v l r) u | v == u = 0
| v < u = 1 + (tWLength l)
| v > u = 1 + (tWLength r)
应该是什么时候
tWLength (Node v l r) u | v == u = 0
| v < u = 1 + (tWLength l u)
| v > u = 1 + (tWLength r u)