Variables F#明确定义的可变变量错误它不是可变变量
我的代码中有几个可变变量。除了一个,所有的都能用Variables F#明确定义的可变变量错误它不是可变变量,variables,f#,mutable,Variables,F#,Mutable,我的代码中有几个可变变量。除了一个,所有的都能用 变量d获取以下几个错误 learn.fsx(33,25): error FS0027: This value is not mutable. Consider using the mutable keyword, e.g. 'let mutable d = expression' 问题是,当您查看我的代码时,该变量显然被定义为可变变量 我认为这是必要的,因为我能想到的唯一应该引起问题的东西是,变量定义之后的东西使它再次不可变 let seq =
变量
d
获取以下几个错误
learn.fsx(33,25): error FS0027: This value is not mutable. Consider using the mutable keyword, e.g. 'let mutable d = expression'
问题是,当您查看我的代码时,该变量显然被定义为可变变量
我认为这是必要的,因为我能想到的唯一应该引起问题的东西是,变量定义之后的东西使它再次不可变
let seq = [2;2;3;3;5;6]
let exp = [[];[]]
let mutable points = 0
let mutable e = 1
let mutable state = ""
let mutable d = 1
let rec guess (x:int) =
match points with
|100 -> "learned"
|_ -> match seq.[x] with
|d -> match (exp.[((List.length exp)-2)]) with
|[] -> if state = "right" then
exp.[((List.length exp)-1)]@[d]
else
state <- "right"
exp@[[d]]
points <- points + 1
if d = 6 then
d <- 1
else
d <- d + 1
if x = 5 then
(guess 0)
else
(guess (x+1))
|_ -> if state = "right" then
exp.[((List.length exp)-1)]@[d]
else
state <- "right"
exp@[[d]]
if (List.length exp.[((List.length exp)-2)]) >= 2 then
d <- (exp.[((List.length exp)-2)]).[e]
else
if d = 6 then
d <- 1
else
d <- d + 1
e <- e + 1
if x = 5 then
(guess 0)
else
(guess (x+1))
|_ -> points <- points - 1
e <- 1
state <- "wrong"
if d = 6 then
d <- 1
else
d <- d + 1
if x = 5 then
(guess 0)
else
(guess (x+1))
让seq=[2;2;3;3;5;6]
设exp=[];[]
设可变点=0
设可变e=1
让可变状态=“”
设可变d=1
让rec猜测(x:int)=
将分数与
|100->“学习”
|_->将序列[x]与
|d->将(exp.[(List.length exp)-2)]与
|[]->如果state=“right”则
exp.[((List.length exp)-1)]@[d]
其他的
状态在匹配中使用d
会导致使用该版本的d
,而不是定义为可变值的d
直接将值的名称更改为其他可用的名称1
例如:|d->match(exp.[((List.length exp)-2)]
可以变成|1->match(exp.[((List.length exp)-2)]
在匹配中使用d
会导致使用该版本的d
而不是定义为可变值的d
直接将值的名称更改为其他可用的名称1
例如:|d->match(exp.[((List.length exp)-2)]
可以变成|1->match(exp.[((List.length exp)-2)]
d
在match
表达式中被隐藏:|d->match(exp.((List.length exp)-2)]with
对不起,我是哑巴了。但这到底是什么意思?或者你所说的“阴影”是什么意思?你已经创建了另一个名为d
的值,当你试图对它进行变异时,它正确地说d
是不可变的,可以称之为d
以外的东西,或者直接使用1
。哦!我明白你的意思!非常感谢!使用时应查看尾部递归函数:特别是有关累加器d
的部分在match
表达式中被隐藏:|d->match(exp.[((List.length exp)-2)],与
非常抱歉,这是一个哑巴。但这到底是什么意思?或者你所说的“阴影”是什么意思?你已经创建了另一个名为d
的值,当你试图对它进行变异时,它正确地说d
是不可变的,可以称之为d
以外的东西,或者直接使用1
。哦!我明白你的意思!非常感谢!使用时应查看尾部递归函数:特别是有关累加器的部分