import Prelude hiding (take) fromTo :: Int -> Int -> [Int] fromTo n m = if n>m then [] else n : fromTo (n+1) m -- List of all ascending numbers starting from its argument: from :: Int -> [Int] from n = n : from (n+1) -- Computes the prefix of a maximal given length from a list take :: Int -> [a] -> [a] take n xs | n <= 0 = [] | otherwise = case xs of [] -> [] (x:xs) -> x : take (n-1) xs -- Compute the infinite list of all primes. sieve :: [Int] -> [Int] sieve (p:xs) = p : sieve (filter (\x -> x `mod` p /= 0) xs) primes :: [Int] primes = sieve (from 2)