I'd like to translate this ML code into F#.
fun take ([], i) = []
| take (x::xs, i) = if i > 0 then x::take(xs, i-1)
else [];
I tried this one
let rec take n i =
match n,i with
| [], i -> []
| x::xs, i -> if i > 0 then x::take(xs, i-1)
else [];
let val = take [1;2;3;4] 3
and this one
let rec take input =
match input with
| ([], i) -> []
| (x::xs, i) -> if i > 0 then x::take(xs, i-1)
else [];
let val = take ([1;2;3;4] 3)
But both of them gives me an error take.fs(7,5): error FS0010: Unexpected keyword 'val' in binding
. What's wrong with the F# code?