Solve accumulator task
This commit is contained in:
parent
245626cb1e
commit
7b1c3220f1
1 changed files with 13 additions and 0 deletions
|
@ -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]
|
||||
--
|
||||
|
|
Loading…
Reference in a new issue