I wrote a basic Eratosthenes's sieve function, that originally ended in head::(innerSieve tail), which I noticed wasn't recursive.
Then I modified it as follows to use an accumulator. This code should be tail recursive now:
let Sieve n =
let rec innerSieve primes numbers =
match numbers with
| [] -> primes
| h :: t -> innerSieve (h :: primes) (List.filter (fun x -> x % h > 0) t)
innerSieve [] [2 .. n] |> List.rev
printf "%A" (Sieve 10000)
However, even in release mode, the memory usage of this function keeps growing extremely fast with the size of n (+1-2MB per every +1000). Am I missing something?
EDIT: Screenshot of VS running it with n = 100M:
