Rekursion über Listen

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

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



Johannes Waldmann 2011-01-18