diff options
author | Yale AI Dept <ai@nebula.cs.yale.edu> | 1993-07-14 13:08:00 -0500 |
---|---|---|
committer | Duncan McGreggor <duncan.mcgreggor@rackspace.com> | 1993-07-14 13:08:00 -0500 |
commit | 4e987026148fe65c323afbc93cd560c07bf06b3f (patch) | |
tree | 26ae54177389edcbe453d25a00c38c2774e8b7d4 /progs/demo/primes.hs |
Import to github.
Diffstat (limited to 'progs/demo/primes.hs')
-rwxr-xr-x | progs/demo/primes.hs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/progs/demo/primes.hs b/progs/demo/primes.hs new file mode 100755 index 0000000..6c8fe79 --- /dev/null +++ b/progs/demo/primes.hs @@ -0,0 +1,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 + |