我必须在haskell中编写一个函数来检查两个二进制树是否是彼此的镜像.这是我到目前为止,但我不知道True && isMirrorImages l1 r2 && areMirrorImages r1 l2是否是正确的方法.我试图用递归调用areMirrorImages函数的结果来逻辑AND True.
-- Tests whether two BinaryTrees are mirror images of one another
areMirrorImages :: (Eq (BinaryTree a), Eq a) => BinaryTree a -> BinaryTree a -> Bool
areMirrorImages Empty Empty = True
areMirrorImages _ Empty = False
areMirrorImages Empty _ = False
areMirrorImages (Node x1 left1 right1) (Node x2 left2 right2) =
if (x1 == x2 && left1 == right2 && right1 == left2)
then True && (areMirrorImages left1 right2) && …Run Code Online (Sandbox Code Playgroud)