-
Notifications
You must be signed in to change notification settings - Fork 833
Description
What
The following code snippet returns a warning that could be improved:
let foo a b = a + b
let x =
foo 5 10
20The warning generated is: -
warning FS0020: This expression should have type 'unit', but has type 'int'. Use 'ignore' to discard the result of the expression, or 'let' to bind the result to a name.
Why
A newcomer to F# will often not understand this; particularly if they come from a statement-focused language where the result of an expression can be arbitrarily discarded. Making this message clearer will not only reduce confusion but could also help new developers understand the value of expressions vs statements.
How
The warning could be improved as follows: -
The expression foo 5 10 returns an int which is currently being ignored. If you do not require this value, you should explicitly ignore it using the ignore function e.g. ignore (foo 5 10) or bind the result to a name e.g. let result = foo 5 10