このツリーのバランスが取れていることを確認するにはどうすればよいですか?
data Tree a = Leaf a | Node (Tree a) (Tree a)
size :: Tree a -> Int
size (Leaf n) = 1
size (Node x z) = size x + size z + 1
これは私がこれまでに持っているものです:
isBalancedTree :: Tree a -> Bool
isBalancedTree (Node l r) = abs (size l - size r) <= 1
&& isBalancedTree l && isBalancedTree r
isBalancedTree _ = False