-
Notifications
You must be signed in to change notification settings - Fork 833
Description
What
The following code raises a compiler warning that a boolean expression is being implicitly ignored.
let x = 10
let y = "hello"
let changeX() =
x = 20
y = "test"warning FS0020: This expression should have type 'unit', but has type 'bool'. Use 'ignore' to discard the result of the expression, or 'let' to bind the result to a name.
Why
For a new developer to F#, they are most likely trying to mutate the values of x and y but do not know about <-. I have seen first hand a developer "fix" these warnings by putting |> ignore after every expression, and then wonder why their application does absolutely nothing at all.
How
The warning should be much clearer: -
The = operator in F# is used for the purposes of comparison, not assignment. Did you intend to set the value of x instead? If so, use the '<-' operator instead e.g. x <- 20.
The remainder of the error message can be the same as in #1108.