What
The following code snippet leads to the resulting error message: -
let x = 5
if !x then "foo" else "bar"
This expression was expected to have type bool ref but here has type int
Why
The error is likely to occur for newcomers to the language who expect it to provide negation behaviour, when F# sees it as ref cell deferefencing, hence the confusing error message. With the improved support for implicit handling of rec cells through the mutable keyword, this error could be reworded to explain that perhaps they meant not instead of !.
How
Suggest an error wording as follows: -
The ! operator is used to dereference a ref cell. Did you want to negate the expression instead? If so, consider using 'not expression' instead.