-->

F#:Block following this 'let' is unfinishe

2019-07-10 02:05发布

问题:

I know in F# we should bind every single value to a name. And I think mine is ok???

But in the if statement I have the following error.

Block following this 'let' is unfinished. Expect an expression

and it comes from let min= List.nth list i. As far as I know I bounded the min to List.nth list i. So why it should be an error?

let mutable list =[-1;2;3;4]
let mutable min=list.[0]
let mutable i=1

if min<=0  then   let  min= List.nth list i  

回答1:

If you want to mutate a mutable variable, you can use the <- operator:

if min <= 0 then min <- List.nth list i  

But this is not a very functional approach. A better method is to define a new value:

let minUpdated = if min <= 0 then List.nth list i else min