Rekursion über Listen

and :: List Bool  -> Bool
and xs = case xs of 
     Nil -> True ; Cons x  xs' -> x && and xs'
length :: List a -> Int
length xs = case xs of
    Nil -> 0 ; Cons x xs' ->  1 + length xs'

fold :: b -> ( a -> b -> b ) -> [a] -> b
fold nil cons xs = case xs of
    Nil -> nil
    Cons x xs' -> cons x ( fold nil cons xs' )
and = fold True (&&) 
length = fold 0 ( \ x y ->  1 + y)



Johannes Waldmann 2011-06-29