Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The problem is not in <code>toTypeList</code> function so you don't have to check whether <code>strArray</code> is empty or not. It will give an error if you check <code>inObj.[0].Length</code> in <code>to2DStrArray</code> function when the input array is empty. A safe way to create an Array2D from an array of array is using <a href="http://msdn.microsoft.com/en-us/library/ee620670.aspx" rel="nofollow">array2D operator</a>:</p> <pre><code>let to2DStrArray (inObj : string[][]) = array2D inObj </code></pre> <p>Of course, you have to guarantee that all inner arrays have the same length. And the other function is shortened as follows:</p> <pre><code>let toTypedList typeFunc (strArray : string[,]) = List.init (Array2D.length1 strArray) typeFunc </code></pre> <p><em>Given your use case, note that</em> [|[||]|] <em>is not an empty string[][]; it is an array which consists of only one element which in turn is an empty string array</em>. Therefore, it causes a problem for the anonymous function you passed to <code>toTypedList</code>. Since the two dimensional array has <code>length2 &lt;= 1</code> and you accesses two first indices, it results in an index of bound exception. The function could be fixed by returning option values, and you can extract values from option values to use later on:</p> <pre><code>let testData = to2DStrArray [|[||]|] let failingCall = testData |&gt; toTypedList (fun row -&gt; if Array2D.length2 testData &gt;= 2 then Some (Double.Parse(testData.[row,0]), Double.Parse(testData.[row,1])) else None) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload