F#:Block following this 'let' is unfinished. Expect an expression

丶灬走出姿态 提交于 2019-12-11 00:30:19

问题


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


来源:https://stackoverflow.com/questions/32720710/fblock-following-this-let-is-unfinished-expect-an-expression

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!