title: Splitting a list at given index f#
body: <p>For a class I'm following, I have to do the following exercise:</p>
  
  <blockquote>
    <p>Implement a function</p>
  
  <pre><code>let splitAt (i : int) (l : List&lt;'a&gt;) : List&lt;'a&gt; * List&lt;'a&gt; = ...
  </code></pre>
    
    <p>that splits the list into two lists, the rst one containing all the elements of l from position 0 to position i
    included, and the second one containing all the remaining elements. The two resulting lists are returned
    in a tuple. For example:</p>
    
    <p>split 3 [3;5;4;-1;2;2] = ([3;5;4;-1],[2;2])</p>
  </blockquote>
  
  <p>We have to do these problems only using functional programming, and thus I'm not allowed to use pre-existing functions.</p>
  
  <p>I have the following code which seems to me to (logically) be correct:</p>
  
  <pre><code>let splitAt (i:int)(l: List&lt;'a&gt;): List&lt;'a&gt; * List&lt;'a&gt; = 
      let rec loop n startlist restlist = 
          if n = i then
              restlist * startlist
          else
              match startlist with
              | h :: t -&gt; loop (n+1) [t] [(restlist :: h)]
              | h :: [] -&gt; None
      loop 0 l []         
  </code></pre>
  
  <p>and below my <code>[&lt;EntryPoint&gt;]</code></p>
  
  <pre><code>printfn "%A" (splitAt stringlist 3)
  </code></pre>
  
  <p>However, this gives me a couple of errors, namely:</p>
  
  <blockquote>
    <p>None of the types <code>'a list</code>, <code>'a list</code> support the operator <code>*</code><br>
    This expression was expected to have type    <code>int</code>    but here has type    <code>char list</code><br>
    This expression was expected to have type    <code>List&lt;'a&gt;</code>    but here has type    <code>int</code></p>
  </blockquote>