I am trying to follow the docs to create an f# program in Visual studio Code
When I highlight my code and press Alt Enter to run in the interactive window I get an error
Script.fsx(8,5):error FS0010: Unexpected keyword in binding. Expected incomplete structured construct at or before this point or other token.
[Update]
I tried several times to get this to work, highlighting the code as the image shows. Strangely after leaving the computer an hour, I now can no longer repeat the problem.
The output visible in the interactive window suggests that your selection when you pressed Alt+Enter was different from the selection you're showing in the screenshot. More specifically, the selection you executed started with let isVowel
(without leading spaces) and ended with word.[0] then
.
Even more specifically, the code you tried to execute was this:
let isVowel (c: char) =
match c with
| 'a' | 'e' | 'i' |'o' |'u'
| 'A' | 'E' | 'I' | 'O' | 'U' -> true
|_ -> false
if isVowel word.[0] then
This code does not compile for several reasons. First, there is nothing after then
. Second, the if
is indented incorrectly: it needs to be indented either to the same position as match
(in which case it will be considered part of isVowel
definition) or to the same position as let isVowel
(in which case it will be considered part of the same block as isVowel
), but here it is neither - to the right of let isVowel
, but to the left of match
.
If you wanted to execute just the definition of isVowel
, then you shouldn't have included the if
in the selection.
If you wanted to execute the whole definition of toPigLatin
, then you should have included the let toPigLatin
line and the whole if/else
expression.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With