不知道这到底是什么问题。我是榆树的新手,所以别紧张。
board = [ [ 'P', 'P', ' ' ], [ ' ', ' ', ' ' ], [ ' ', ' ', ' ' ] ]
move = nextBestMove board
nextBestMove : List (List Char) -> Int
nextBestMove gameNode =
let
node =
map fromList gameNode
-- node is now List (Array.Array Char)
currentBoard =
fromList node
-- currentBoard is now Array.Array (Array.Array Char)
row1 =
get 0 currentBoard
-- row1 is now Maybe.Maybe (Array.Array Char)
-- now I want to place an X for the empty value in [ 'P', 'P', ' ' ]
row1NextState =
set 2 'X' row1
... rest of code
我得到的类型不匹配错误是:
The 3rd argument to function `set` is causing a mismatch.
22| set 2 'X' row1
^^^^
Function `set` is expecting the 3rd argument to be:
Array.Array Char
But it is:
Maybe (Array.Array Char)
我不明白为什么我现在认为我有一个二维数组,它应该是好的。我想要做的是得到一个指向我的棋盘第一行的指针。所以我想从本质上说,这样我就可以更新行[ 'P', 'P', ' ' ]
中的空位置了
发布于 2018-09-11 18:03:38
正如您已经注意到的,到达函数将产生一个Maybe
类型。这意味着我们需要将Maybe
类型转换为Array
类型,以便在set
中使用它。我们可以在这里使用像withDefault这样的函数。
row1NextState =
set 2 'X' (withDefault (Array.initialize 3 (always ‘X’)) row1)
这使得榆树在row1
是Nothing
的情况下使用Nothing
。
https://stackoverflow.com/questions/52281595
复制相似问题