Avoiding mutable booleans indicating state
<p>Suppose that before you enter a long running process, you have to perform some pre-start checks. </p>

<p>Suppose also that once these checks are satisfied you do not need to do the checks again (perhaps there are many of these checks and are also relatively expensive to perform). </p>

<p>How can state be avoided here?</p>

<p>More generally, in Python, you could have something like a generator or coroutine which could hold these checks and state. Is there a nice F-sharpy way of getting rid of the mutable booleans to indicate skipping each of the satisfied checks?</p>

<pre><code>let r = new System.Random()

let someCondition1 () = 
    r.Next() % 523452321 = 0 

let someCondition2 () = 
    r.Next() % 243142321 = 0 

let mutable conditionCheck1 = false
let mutable conditionCheck2 = false
let rec conditionChecks () =

    match conditionCheck1 with
    | true -&gt; ()
    | false -&gt; match someCondition1 () with
               | false -&gt; conditionChecks ()
               | true  -&gt; conditionCheck1 &lt;- true // never check again

    match conditionCheck2 with
    | true -&gt; ()
    | false -&gt; match someCondition2 () with
               | false -&gt; conditionChecks ()
               | true  -&gt; conditionCheck2 &lt;- true // never check again

let rec eventLoop () =
    eventLoop ()

conditionChecks ()
eventLoop ()
</code></pre>