carrotzoe
carrotzoe

Reputation: 147

haskell sieve prime number

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

Answers (1)

[ x | x <- xs, x `mod` p > 0] is a list of xs 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

Related Questions