import Prelude hiding (take) f x = 1 loop = loop g True = False -- Infinite list of numbers from :: Int -> [Int] from n = n : from (n + 1) -- Take the first n elements of a list: take :: Int -> [a] -> [a] take n xs | n <= 0 = [] | otherwise = case xs of [] -> [] (x:xs) -> x : take (n - 1) xs -- Sieve of Eratosthenes: sieve :: [Int] -> [Int] sieve (p:xs) = p : sieve (filter (\x -> x `mod` p > 0) xs) -- The list of all prime numbers: primes :: [Int] primes = sieve (from 2)