diff --git a/Exercises/exercise-4/Solution.hs b/Exercises/exercise-4/Solution.hs index 1edb5a2..255caae 100644 --- a/Exercises/exercise-4/Solution.hs +++ b/Exercises/exercise-4/Solution.hs @@ -54,3 +54,16 @@ length' ls = aux x : xs -> aux $ map (\y -> (+1) x ) xs -- length' und aux sind nicht endrekursiv +-- sieve :: ( a -> a -> Bool ) -> [ a ] -> [ a ] +-- sieve pred xs = case xs of +-- [] -> [] +-- x : xs -> x :( sieve pred $ filter ( pred x ) xs ) +sieve :: (a -> a -> Bool) -> [a] -> [a] +sieve pred xs = realSieve [] xs + where + realSieve acc [] = acc + realSieve acc (x : xs) = realSieve (acc ++ [x]) (filter (pred x) xs) + +-- >>> sieve (\ x -> \ y -> y > x) [1, 2, 3, 1, 2, 9, 7] +-- [1,2,3,9] +--