f :: Tree a -> b
f t = case t of
Leaf {} -> ...
Branch {} ->
... (f (left t)) (key t) (f (right t))
dieses Schema ist eine Funktion höherer Ordnung:
fold :: ( ... ) -> ( ... ) -> ( Tree a -> b )
fold leaf branch = \ t -> case t of
Leaf {} -> leaf
Branch {} ->
branch (fold leaf branch (left t))
(key t) (fold leaf branch (right t))
summe = fold 0 ( \ l k r -> l + k + r )