sieve [] = []
sieve (a:x) = a : sieve [y| y <- x, y `mod` a > 0]
I want to convert this code to recursive implementation or using higher order functions such as map and filter. I can't figure out how do I do this.
I have tried this way but it wont seem to work
sieve (a:x) = f x : map f xs where f = y `mod` a > 0
Is this the kind of thing you want? The list comprehension is only being used to filter the list anyway, so we can convert to a form that manually applies a filter.