There was an error while loading. Please reload this page.
1 parent 2ac11f2 commit 00ec503Copy full SHA for 00ec503
chapter08-Declaring-types-and-classes/3.hs
@@ -0,0 +1,10 @@
1
+data Tree a = Leaf a | Node (Tree a) (Tree a)
2
+
3
+count :: Tree a -> Int
4
+count (Leaf _) = 1
5
+count (Node l r) = count l + count r + 1
6
7
+balanced :: Tree a -> Bool
8
+balanced (Leaf _) = True
9
+balanced (Node l r) = abs (lcount - rcount) <= 1 && balanced l && balanced r
10
+ where lcount = count l; rcount = count r
0 commit comments