Last active
August 29, 2015 14:15
-
-
Save motylwg/9788f95f0ac9bb147e02 to your computer and use it in GitHub Desktop.
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
let rec sieve (xs : int seq) = | |
seq { | |
let p = xs |> Seq.take 1 |> Seq.exactlyOne | |
yield p | |
yield! xs |> Seq.skip 1 |> Seq.filter (fun x -> x % p <> 0) |> sieve | |
} | |
let ints = Seq.initInfinite (fun x -> x + 2) | |
let primes = sieve ints |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note: This is not the genuine Sieve of Eratosthenes but rather the inefficient naive sieve.
See http://www.cs.hmc.edu/~oneill/papers/Sieve-JFP.pdf for details.