Skip to content

Commit 00ec503

Browse files
committed
[exercise] 8.3
1 parent 2ac11f2 commit 00ec503

File tree

1 file changed

+10
-0
lines changed
  • chapter08-Declaring-types-and-classes

1 file changed

+10
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)