Solve continuation task
This commit is contained in:
parent
7b1c3220f1
commit
7b0feead6e
|
@ -67,3 +67,13 @@ sieve pred xs = realSieve [] xs
|
||||||
-- >>> sieve (\ x -> \ y -> y > x) [1, 2, 3, 1, 2, 9, 7]
|
-- >>> sieve (\ x -> \ y -> y > x) [1, 2, 3, 1, 2, 9, 7]
|
||||||
-- [1,2,3,9]
|
-- [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]
|
||||||
|
--
|
||||||
|
|
Loading…
Reference in a new issue