F#明确定义了可变变量错误,它不是一个可变变量

Nul*_*lle 0 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'
Run Code Online (Sandbox Code Playgroud)

问题是当你查看我的代码时,变量显然被定义为一个可变变量.

我认为这是必要的,因为我能想到的唯一能引起问题的是它是变量定义之后的东西,它使它再次变得不可变.

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))
Run Code Online (Sandbox Code Playgroud)

Mr.*_*Mr. 5

d在匹配中使用会导致使用该版本d而不是d定义为可变值.

将值的名称1直接更改为其他用途.

例如:| d -> match (exp.[((List.length exp)-2)])可以成为| 1 -> match (exp.[((List.length exp)-2)])