Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Block is unfinished

Tags:

f#

This code fragment is compiled:

let test =
    let x = 1
    printfn "%A" x

If the last line is removed, there is the following compilation error:

error FS0588: Block following this 'let' is unfinished. Expect an expression.

What does this message mean? In C#/C++ I would expect the "Unused variable" warning in such situation, but F# gives something different.

like image 288
Alex F Avatar asked Feb 20 '11 08:02

Alex F


1 Answers

In F#, a function has to bind a name to a value.

The printfn statement has a return value, and this is ultimately what gets bound to test.

Without the printfn statement you only have a statement binding the value 1 to x. The compiler will be expecting something to bound to test. Because the test function stops at this point, this is why you are seeing the compiler errror.

If you want your function just to do stuff (possibly with side effects), you should end your function with ()

like image 83
Jimmy Avatar answered Sep 19 '22 20:09

Jimmy