Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual studio - f# - Error FS0588 : Block following this 'let' is unfinished. Expect expression

Tags:

f#

i have got several times , trying to implement different functions, the message you see as title. I would like to know if anyone can tell me the general meaning (and reason) of this error message. As i mentioned before, i have got the problem several times and manage to fix it, but still didnt get the exact reason, so i will not post any specific code.

Thank you in advance

like image 266
tropicana Avatar asked Dec 17 '22 09:12

tropicana


1 Answers

The most common case when you may get this error is when you write let binding that is not followed by an expression that calculates the result. In F#, everything is an expression that returns some result, so if you write let a = 10 it is generally not a valid expression. To make it valid, you need to return something:

let foo () = 
  let a = 10
  () // return unit value (which doesn't represent any information)

The only exception where you can write just let a = 10 is a global scope of an F# source file - for example, inside a module declaration or in an F# script file. (This is why the declaration of foo above is valid).

It is difficult to give any advice without seeing your code, but you probably have a let declaration that is not followed by an F# expression.

Out of curiosity, the following example shows that let can really be used inside an expression (where it must return some meaningful result):

let a = 40 + (let a = 1 
              a + a)
like image 87
Tomas Petricek Avatar answered May 11 '23 01:05

Tomas Petricek