Last active
December 14, 2015 04:59
-
-
Save aanand/5031784 to your computer and use it in GitHub Desktop.
Un-genuine Sieve of Eratosthenes in Haskell
This file contains hidden or 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
$ ghci sieve.hs | |
*Main> take 10 primes | |
[2,3,5,7,11,13,17,19,23,29] |
This file contains hidden or 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
primes = sieve [2..] | |
sieve (x:xs) = x : sieve [n | n <- xs, n `mod` x > 0] |
Nice find Reg. I love that the example code is identical to the one I typed from memory (disregarding whitespace and variable identifiers).
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
primes take 10 foreach println
is equivalent toprimes.take(10).foreach(println)
, right? Oh, Scala.