Skip to content

Instantly share code, notes, and snippets.

@luochen1990
Last active September 16, 2015 13:32
Show Gist options
  • Save luochen1990/29086276dd4bed5bb1d4 to your computer and use it in GitHub Desktop.
Save luochen1990/29086276dd4bed5bb1d4 to your computer and use it in GitHub Desktop.
isPrime x = all (\p -> x `mod` p /= 0) . takeWhile ((<= x) . (^ 2)) $ primes
primes = 2 : 3 : filter isPrime [5..]
ghci> let (isPrime, primes) = ((\x -> all (\p -> x `mod` p /= 0) . takeWhile((<= x) . (^2)) $ primes), 2 : 3 : filter isPrime [5..])
ghci> take 10 primes
[2,3,5,7,11,13,17,19,23,29]
ghci> takeWhile (< 100) primes
[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment