Solve accumulator task

This commit is contained in:
Manuel Thalmann 2024-06-16 14:37:03 +02:00
parent 245626cb1e
commit 7b1c3220f1

View file

@ -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]
--