I’m probably missing something very fundamental here but I can’t figure out what it is.
I have some very basic code as below:
let myList = [1; 3; 5; 7; 5; 3; 9; 5; 2; 5; 3; 8]
let fiveOrLess = myList |> List.choose (fun number ->
match number with
| number when number <= 5 -> Some number
| _ -> None)
… and that works just fine, as expected.
However, with the code below, where I have moved the “myList” from the pipe to just being a ‘normal’ parameter, I get two error messages from the compiler:
let myList = [1; 3; 5; 7; 5; 3; 9; 5; 2; 5; 3; 8]
let fiveOrLess = List.choose (fun number ->
match number with
| number when number <= 5 -> Some number
| _ -> None) myList
Error FS3118 Incomplete value or function definition. If this is in an expression, the body of the expression must be indented to the same column as the 'let' keyword. [This error on the second ‘let’.]
Error FS0010 Unexpected identifier in binding. Expected incomplete structured construct at or before this point or other token. [This error on the last “myList”.]
Nether of these error messages makes much sense to me as all I have done is move a parameter ‘from one side to the other’.
The documentation here: https://msdn.microsoft.com/visualfsharpdocs/conceptual/list.choose%5b%27t%2c%27u%5d-function-%5bfsharp%5d shows code which has a very similar form to my second sample but that works okay.
Can anyone explain what silly, basic mistake I’ve made here? Also, and possibly more importantly, can anyone explain what the error messages mean and why I’m getting them, both in general and in this context please?