F#:Block following this 'let' is unfinishe

2019-07-10 02:11发布

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条回答
时光不老,我们不散
2楼-- · 2019-07-10 02:47

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
查看更多
登录 后发表回答