(*) A list of prime numbers.
Given a range of integers by its lower and upper limit, construct a list of all prime numbers in that range.
primesR :: Integral a => a -> a -> [a] primesR a b = filter isPrime [a..b]
If we are challenged to give all primes in the range between a and b we simply take all number from a up to b and filter the primes out.
primes :: Integral a => [a] primes = let sieve (n:ns) = n:sieve [ m | m <- ns, m `mod` n /= 0 ] in sieve [2..] primesR :: Integral a => a -> a -> [a] primesR a b = takeWhile (<= b) $ dropWhile (< a) primes