 <p>Your immediate problem is that you need parentheses around <code>(List.length xs)</code>. The code also treats an empty input list as an error in all cases, which is not correct. An empty list is a legitimate input if the desired length <code>k</code> is 0.</p> <p><strong>Update</strong></p> <p>You also have one extra parameter in your definition. If you say this:</p> <pre><code>let myfun k xs = function ... </code></pre> <p>the function <code>myfun</code> has 3 parameters. The first two are named <code>k</code> and <code>xs</code> and the third is implicitly part of the <code>function</code> expression.</p> <p>The quick fix is just to remove <code>xs</code>.</p> <p>I think you might be asking for the wrong number of elements in your recursive call to <code>take</code>. Something to look at anyway.</p>