You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
F# treats: 2-1(no spaces)
and 2 - 1(spaces surround minus sign from both sides)
the same, but 2 -1 (space before minus sign, but not after).
is treated differently.
This can lead to a very easy to make, but hard to get right error messages for newcomers to the language.
(Source: I was/still am this newcomer)
Code examples
Example 1:
let minusOne x = x -1
let twoPlusThreeMinusOne = 2 + minusOne 3
Would lead to: error FS0001: This expression was expected to have type 'int -> 'a' but here has type 'int'
Example 2:
let getListWithoutFirstAndLastElement list =
let l = List.length list
list[1 .. l -2]
Would lead to: error FS0003: This value is not a function and cannot be applied.
Why
For newcomers to the language, the difference between -1 and - 1 is very odd. I know, because just recently I was that newcomer and this is the error that was the weirdest for me to debug.
How to improve
I assume treating "-1" as "- 1" in those instances is out of the question.
So the best thing I can think of right now for Example 2 with error like this is explanation that -1 is treated as a negation not as subtraction.
error FS0003: This value is not a function and cannot be applied.
warning: list[1 .. List.length list -1]
-1 is a negation not subtract operation. To get subtraction use „ - „
This one is pretty difficult - so much so that in Ionide we added a code-fix to fix this automatically. It would be good to be able to have a more useful error message to make that codefix less necessary.
Problem / Potential Improvement
F# treats:
2-1
(no spaces)and
2 - 1
(spaces surround minus sign from both sides)the same, but
2 -1
(space before minus sign, but not after).is treated differently.
This can lead to a very easy to make, but hard to get right error messages for newcomers to the language.
(Source: I was/still am this newcomer)
Code examples
Example 1:
Would lead to:
error FS0001: This expression was expected to have type 'int -> 'a' but here has type 'int'
Example 2:
Would lead to:
error FS0003: This value is not a function and cannot be applied.
Why
For newcomers to the language, the difference between -1 and - 1 is very odd. I know, because just recently I was that newcomer and this is the error that was the weirdest for me to debug.
How to improve
I assume treating "-1" as "- 1" in those instances is out of the question.
So the best thing I can think of right now for Example 2 with error like this is explanation that -1 is treated as a negation not as subtraction.
error FS0003: This value is not a function and cannot be applied.
warning: list[1 .. List.length list -1]
-1 is a negation not subtract operation. To get subtraction use „ - „
I don’t have a good idea how to fix example 1.
Related: #1103
The text was updated successfully, but these errors were encountered: