以下代码提供错误The operator 'expr.[idx]' has been used an object of indeterminate type based on information prior to this program point. Consider adding further type constraints
。我想我告诉过它的类型。有什么问题?
let board = Array2D.init 30 30 (fun x y -> 0)
let tickCell x y board : int[,] =
match board with
|board when board.[x].[y] = 0-> 1
|board when board.[x].[y] = 1-> 0
| _ -> -1
let board2 = Array2D.init 30 30 (fun x y -> tickCell x y board)
答案 0 :(得分:2)
这些小改动应该摆脱错误:
board
参数并输入括号使用[x,y]
let tickCell x y (board : int[,]) =
match board with
|board when board.[x,y] = 0-> 1
|board when board.[x,y] = 1-> 0
| _ -> -1