F# using sequence cache correctly <p>I'm trying to use Seq.cache with a function that I made that returns a sequence of primes up to a number N excluding the number 1. I'm having trouble figuring out how to keep the cached sequence in scope but still use it in my definition.</p> <pre><code>let rec primesNot1 n = {2 .. n} |&gt; Seq.filter (fun i -&gt; (primesNot1 (i / 2) |&gt; Seq.for_all (fun o -&gt; i % o &lt;&gt; 0))) |&gt; Seq.append {2 .. 2} |&gt; Seq.cache </code></pre> <p>Any ideas of how I could use Seq.cache to make this faster? Currently it keeps dropping from scope and is only slowing down performance.</p>