Reputation: 147
In the following prime sieve:
primes :: [Integer]
primes = sieve [2..]
where
sieve (p:xs) = p : sieve [x|x <- xs, x `mod` p > 0]
What do x | x <- xs
and x `mod` p > 0
mean?
Upvotes: 0
Views: 493
Reputation: 8069
[ x | x <- xs, x `mod` p > 0]
is a list of x
s made of elements from xs
, but only those elements that satisfy the x `mod` p > 0
condition (mod
returns the remainder after the first number is divided by the second number, so you're asking for elements of xs
that aren't divisible by p
).
Upvotes: 2