Last active
August 29, 2015 14:11
-
-
Save eush77/7c537ca0211670dfb184 to your computer and use it in GitHub Desktop.
Stream of prime numbers, this time in Haskell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- SICP 3.5.2: https://sarabander.github.io/sicp/html/3_002e5.xhtml#g_t3_002e5_002e2 | |
sieve :: Integral a => [a] -> [a] | |
sieve (n : ns) = n : sieve (filter (\x -> x `mod` n /= 0) ns) | |
primes :: [Integer] | |
primes = sieve [2..] | |
main :: IO () | |
main = let ns = take 100 primes | |
in putStrLn $ concat [show n ++ ", " | n <- ns] ++ "..." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment