You only need a leaf function.

My solution is like Wieslav’s but for beginners ðŸ™‚

foldt fl fb (Leaf x) = fl x

foldt fl fb (Branch t1 t2) = fb t1′ t2′

where

t1′ = foldt fl fb t1

t2′ = foldt fl fb t2

fringe t = foldt tolist (++) t where tolist x = [x]

treeSize t = foldt one (+) t where one x = 1

treeHeight t = foldt zero max1 t

where

zero x = 0

max1 t1 t2 = 1 + max t1 t2

foldTree _ init (Leaf x) = init x

foldTree op init (Branch t1 t2) = (foldTree op init t1) `op` (foldTree op init t2)

fringe’ = foldTree (++) (:[])

treeSize’= foldTree (+) (const 1)

treeHeight’= foldTree (\x y->max x y+1) (const 0)