summaryrefslogtreecommitdiff
path: root/progs/demo/primes.hs
blob: 6c8fe79919b14bf29d745a59a9c8d22103a8e849 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
-- This program implements Eratosthenes Sieve
-- to generate prime numbers.

module Main where

primes :: [Int]
primes = map head (iterate sieve [2 ..])

sieve :: [Int] -> [Int]
sieve (p:ps) = [x | x <- ps, (x `mod` p) /= 0]

main = appendChan stdout "How many primes? " abort $
       readChan stdin abort $ \ input ->
       appendChan stdout (show (take (read (head (lines input))) primes))
	                 abort done