Haskell 哈斯克尔方程二叉树(镜像)

Haskell 哈斯克尔方程二叉树(镜像),haskell,Haskell,你好,我有一些关于哈斯克尔的家庭作业 The definition of a binary tree has the form: data Tree a = Leaf a | Node a (Tree a) (Tree a) | null Enter the implementation of the equal function checking whether the two binary trees are identical. Ti

你好,我有一些关于哈斯克尔的家庭作业

The definition of a binary tree has the form:

data Tree a = Leaf a
             | Node a (Tree a) (Tree a)
             | null
Enter the implementation of the equal function checking whether the two binary trees are identical.

Tip
equal :: Eq a => Tree a -> Tree a -> Bool
equal Null Null = {- ... -}
equal {- ... -} = a == b
equal (Node a1 left1 right1) {- ... -} = a1 == a2 && {- ... -}
equal _ _ = False
In the above outline of implementation, replace comments {- ... -} into the appropriate code.
这是我的家庭作业,我发现了一些东西,但我想不出一件事

equal :: Eq a => Tree a -> Tree a -> Bool
equal Null Null = True
equal a (Leaf b) = a == b
equal (Node a1 left1 right1) (Node a2 left2 right2) = a1 == a2 && equal left1 right2 && equal right1 left2
equal _ _ = False
这是我的代码,
等于a(叶b)=a==b
这部分不工作。我没有找到我应该放在那里的东西。

那行:

equal a (Leaf b) = a == b
将导致类型不匹配,应替换为:

equal (Leaf a) (Leaf b) = a == b

您已经使用了
类型的构造函数
节点
Null
,但是还有第三个构造函数。您在那里编写的内容取决于您想要的内容。为什么要问我们?@epsilonhalbe,我实际上认为这些提示看起来结构非常糟糕,涉及各种不同的方向。我个人从左到右暗示,这也是我如何编码的。展示这些模式,让学员了解它们应该发生什么。