How to recursively use FsCheck generators?
<p>I use FsCheck for property-based testing, so I defined a set a generators for custom types. Some of types are composed of others, and there are generators for all of them. Having defined a generator for Alphanumeric type, I want to define a generator for RelativeUrl type, and RelativeUrl is list of 1-9 Alphanumeric values separated by slash symbol. Here's the definition that works (Alpanumeric has "Value" property that converts it to String):</p>

<pre><code>static member RelativeUrl() =
    Gen.listOfLength (System.Random().Next(1, 10)) &lt;| Generators.Alphanumeric()
    |&gt; Gen.map (fun list -&gt; String.Join("/", list |&gt; List.map (fun x -&gt; x.Value)) |&gt; RelativeUrl)
</code></pre>

<p>Even though it's quite simple I don't like that I use Random.Next method instead of using FsCheck random generators. So I tried to redefine it like this:</p>

<pre><code>static member RelativeUrl_1() =
    Arb.generate&lt;byte&gt; 
    |&gt; Gen.map int 
    |&gt; Gen.suchThat (fun x -&gt; x &gt; 0 &amp;&amp; x &lt;= 10)
    |&gt; Gen.map (fun length -&gt; Gen.listOfLength length &lt;| Generators.Alphanumeric())
    |&gt; Gen.map (fun list -&gt; String.Join("/", list))
</code></pre>

<p>Compiler accepts it but in fact it's wrong: a "list" in the last statement is not a list of Alphanumeric values but a Gen. Next attempt:</p>

<pre><code>static member RelativeUrl() =
    Arb.generate&lt;byte&gt; 
    |&gt; Gen.map int 
    |&gt; Gen.suchThat (fun x -&gt; x &gt; 0 &amp;&amp; x &lt;= 10)
    |&gt; Gen.map (fun length -&gt; Gen.listOfLength length &lt;| Generators.Alphanumeric())
    |&gt; Gen.map (fun list -&gt; list |&gt; Gen.map (fun elem -&gt; String.Join("/", elem |&gt; List.map (fun x -&gt; x.Value))  |&gt; RelativeUrl))
</code></pre>

<p>But this doesn't work either: I am getting back Gen of Gen of RelativeUrl, not Gen of RelativeUrl. So what would be a proper way of combining generators at different levels?</p>