How to use pattern matching within curried function I'm learning F# and I'm trying the following exercise (exercise 4.10 of Functional Programming Using F#).


  Declare an F# function prefix: 'a list -&gt; 'a list -&gt; bool when a:equality. The value of the expression prefix[x_0;x_1;...;x_m] [y_0;y_1;...;y_n] is true if m&lt;=n and x_i=y_i for 0&lt;=i&lt;=m, and false otherwise.


I wanted to use pattern matching on the two inputs, but wasn't sure how to do this with a curried function (as opposed to a function taking a 2-tuple). So I wrote:

let rec prefix a b = (function
    | ([], _) -&gt; true
    | (_, []) -&gt; false
    | (x0::xst,y0::yst) -&gt; x0 = y0 &amp;&amp; prefix xst yst) (a,b);;


I wasn't very happy with this, because I thought it would be better (clearer and more efficient) if the inner function called itself, so I tried declaring the inner function locally.

let prefix a b =
    let rec prefixt = function
        | ([], _) -&gt; true
        | (_, []) -&gt; false
        | (x0::xst,y0::yst) -&gt; x0 = y0 &amp;&amp; prefixt (xst,yst)
    prefixt (a,b);;


Is this the right way to approach such a problem in F#?
You can use the match … with … syntax:

let rec prefix a b =
    match (a, b) with
    | ([], _) -&gt; true
    | (_, []) -&gt; false
    | (x0::xst,y0::yst) -&gt; x0 = y0 &amp;&amp; prefix xst yst