99-haskell-problems/Problems 61-69/problem_61.hs

8 lines
247 B
Haskell

data Tree a = Empty | Branch a (Tree a) (Tree a)
deriving (Show, Eq)
countLeaves :: Tree a -> Int
countLeaves Empty = 0
countLeaves (Branch _ Empty Empty) = 1
countLeaves (Branch _ branch1 branch2) =
countLeaves branch1 + countLeaves branch2