Reputation: 49
I am trying to run below F# code however getting error "Receiving error "Block following 'let' is unfinished". expect an expression". Any thought on this?
let search func list =
let rec loop func list index =
match list with
| [] -> -1
| hd::tl -> if func hd then index
else loop func tl(index+1) loop func list 0
Upvotes: 2
Views: 379
Reputation: 6324
You can paste a code block, so no need to format line by line. The error you see, is almost always comes from two (related) issues, a) the indent is off, b) either because the indent is off, or you just forgot to return a value from the function. This is rarely an issue because both VS and Code can use indent lines or depth colorization so you can immediately see what's off.
Did you mean something like this:
let search func list =
let rec loop func list index =
match list with
| [] -> -1
| hd::tl -> if (func hd) then index
else loop func tl (index+1)
loop func list 0
Upvotes: 1