Solve continuation task

This commit is contained in:
Manuel Thalmann 2024-06-16 14:56:36 +02:00
parent 7b1c3220f1
commit 7b0feead6e

View file

@ -67,3 +67,13 @@ sieve pred xs = realSieve [] xs
-- >>> sieve (\ x -> \ y -> y > x) [1, 2, 3, 1, 2, 9, 7]
-- [1,2,3,9]
--
sieveC :: (a -> a -> Bool) -> [a] -> [a]
sieveC pred xs = realSieve id xs
where
realSieve f [] = f []
realSieve f (x : xs) = realSieve (\ items -> filter (pred x) (f items)) xs
-- >>> sieve (\ x -> \ y -> y > x) [6, 2, 3, 1, 2, 9, 7]
-- [6,9]
--