title: What's wrong with this List expression?
body: <p>I have a recursive function that creates a tree like so:</p>
  
  <pre><code>let rec evaluate node = 
      let neighbors = getNeighbors node
      let visited = [for x, y in neighbors do
                         if not tiles.[y].[x] then
                             tiles.[y].[x] &lt;- true
                             evaluate (x, y)]
      if List.length visited &gt; 0 then 
          Node(x, y, visited) 
      else 
          Leaf(x, y)
  </code></pre>
  
  <p>Node and Leaf come from this definition:</p>
  
  <pre><code>type Tree =
      | Leaf of int * int
      | Node of int * int * Tree list
  </code></pre>
  
  <p>and <code>tiles</code> is a 2-dimensional array of booleans representing which tiles have been visited (I'm implementing maze generation).</p>
  
  <p>Now the above function does not compile. The inferred type is <code>int*int -&gt; unit</code>, when it should be <code>int*int -&gt; Tree</code>.</p>
  
  <p>I attempted to force the return type to be <code>Tree</code>, but then the compiler complains that the call to evaluate should have type <code>unit</code> but has type <code>Tree</code>.</p>
  
  <p>I have found a workaround using a sequence expression and converting to list:</p>
  
  <pre><code>let visited = Seq.toList (seq { 
                  for x, y in neighbors do
                      if not tiles.[y].[x] then
                          tiles.[y].[x] &lt;- true
                          yield evaluate (x, y)})
  </code></pre>
  
  <p>But I don't understand why using a list expression doesn't work.</p>