Rekursion über Bäume (Beispiele)

data Tree a    = Leaf 
  | Branch ( Tree a ) a ( Tree a )
summe :: Tree N -> N
summe t = case t of
  Leaf -> Z
  Branch l k r -> 
    plus (summe l) (plus k (summe r ))
preorder :: Tree a -> List a
preorder t = case t of
  Leaf -> Nil
  Branch l k r -> 
   Cons k (append (preorder l) 
                  (preorder r))



Johannes Waldmann 2011-06-29