Since it valis a reserved keyword in F #, you cannot use it as a value. Your first version takeis incorrect, because the type take(xs, i-1)(tuple) is different from the type take n i(curry). It works:
let rec take n i =
match n, i with
| [], i -> []
| x::xs, i -> if i > 0 then x::(take xs (i-1)) else []
let value = take [1;2;3;4] 3
The second version has an error in the way you call the function. It can be fixed as follows:
let rec take input =
match input with
| [], i -> []
| x::xs, i -> if i > 0 then x::take(xs, i-1) else []
let value = take ([1;2;3;4], 3) // Notice ',' as tuple delimiter
Or you can write even closer to your ML function:
let rec take = function
| [], i -> []
| x::xs, i -> if i > 0 then x::take(xs, i-1) else []
let value = take ([1;2;3;4], 3)
source
share