Funktionen auf Alg. Datentypen

data Node k = Leaf   { key :: k }
    | Branch { key :: k, left :: Node k, right :: Node k }
(vollst.) Fallunterscheidung nach den Konstruktoren:
children :: Node k -> [ Node k ]
children = \ n -> case n of
    Branch {} -> [ left n, right n ]
    Leaf   {} -> [ ]
alternative Schreibweise: pattern matching
children = \ n -> case n of
    Branch { left = l, right = r } -> [ l, r ]
    Leaf   { } -> [ ]



2009-11-20