I've created the following iterative prime sieve in C#
static IEnumerable Primes()
{
yield return 2;
Dictionary sieve = new Dictionary();
for(int i = 3;; i += 2)
{
int marker;
if(!sieve.TryGetValue(i, out marker))
{
yield return i;
marker = i;
}
int step = marker + marker, x = marker + step;
while(sieve.ContainsKey(x))
x += step;
sieve.Add(x, marker);
}
}
And now I wonder how do I "translate" it to F# I've found "Seq.unfold" and I guess that's half the answer but the other half I seem to not really get.
Any help greatly appriciated.