What
Related to #1104, but not the same. The following code leads to an especially cryptic error message from the compiler:
let x = 10
let y =
if x < 10 then "test"
elif x < 20 then "foo"
As if is an expression in F#, you need to provide an else branch as well. The error message shown below is related to the elif branch above (but not the if branch): -
error FS0001: This expression was expected to have type
string
but here has type
unit
Why
What's especially confusing about this error (in addition to the points put forward in #1104) is that the error suggests that the type being returned from this branch is a unit when in fact it is a string. Even worse, if you comment out the elif branch so that you just have the if branch, the types in the error message become inverted!
How
As per #1104.