I'm learning F# and I'm trying the following exercise (exercise 4.10 of Functional Programming Using F#).
Declare an F# function
'a list -> 'a list -> bool when a:equality. The value of the expression
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 | (, _) -> true | (_, ) -> false | (x0::xst,y0::yst) -> x0 = y0 && 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 | (, _) -> true | (_, ) -> false | (x0::xst,y0::yst) -> x0 = y0 && prefixt (xst,yst) prefixt (a,b);;
Is this the right way to approach such a problem in F#?