import Prelude hiding (take) -- Evaluating expressions: f x = 1 h = h -- Returns an ascending list of integers -- from 0 --> 0 : 1 : 2 : 3 : ... from :: Int -> [Int] from n = n : from (n + 1) -- Returns 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: filter multiples of initial elements sieve :: [Int] -> [Int] sieve (p:xs) = p : sieve (filter (\x -> x `mod` p > 0) xs) -- The infinite list of all prime numbers: primes :: [Int] primes = sieve (from 2)