Pattern Matching

data Tree a  = Leaf a
    | Branch ( Tree a ) ( Tree a )
Verarbeitung von Objekten dieses Typs:
leaves :: Tree a -> Int
leaves t = case t of
    Leaf k -> 1
    Branch l r -> leaves l + leaves r



Johannes Waldmann 2011-07-07