F#:此"let"之后的块未完成.期待表达 [英] F#:Block following this 'let' is unfinished. Expect an expression
本文介绍了F#:此"let"之后的块未完成.期待表达的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道在F#中,我们应该将每个值绑定到一个名称. 而且我认为我还可以吗?
I know in F# we should bind every single value to a name. And I think mine is ok???
但是在 if语句中,我遇到了以下错误.
But in the if statement I have the following error.
Block following this 'let' is unfinished. Expect an expression
,它来自let min= List.nth list i
.
据我所知,我将 min 限制为List.nth list i
.那么为什么应该是一个错误呢?
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
推荐答案
如果要变异可变变量,可以使用<-
运算符:
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
这篇关于F#:此"let"之后的块未完成.期待表达的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文