Elm Array.set需要Array.Array字符,但可能需要获取(Array.Array字符)

Elm Array.set需要Array.Array字符,但可能需要获取(Array.Array字符),elm,Elm,我不知道到底是什么问题。我是榆树的新手,所以别紧张 board = [ [ 'P', 'P', ' ' ], [ ' ', ' ', ' ' ], [ ' ', ' ', ' ' ] ] move = nextBestMove board nextBestMove : List (List Char) -> Int nextBestMove gameNode = let node = map fromList gameNode

我不知道到底是什么问题。我是榆树的新手,所以别紧张

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)
我不明白为什么,因为我认为现在我有了一个二维数组,它应该可以运行了。我想做的是让指针指向我游戏板的第一行。所以我想从[0][0]开始,这样我就可以更新第
['P','P',''']

行中的空位,正如您所注意到的,该函数会输出一个

可能
类型。这意味着我们需要将
可能
类型转换为
数组
类型,以便在
集合
中使用它。我们可以使用这样的函数


这使得elm在
row1
Nothing

的情况下使用
['X','X','X']
,您是否试图将行中的空位设置为X?所以
['P','P','X']
是的..这正是我想要做的。我只是不明白为什么这里可能有人。。以及为什么它在度量出的行上出错,但是get函数
set
需要3个参数,但得到了4个。21 |使用默认值(['X',X',X']row1)设置2'X',该值应为3个参数。。。
set 2'X(默认为[X',X',X']row1)
我们需要
()
围绕第三个参数的原因是
set
知道它的一个参数。否则,当我们真正想要整个函数的结果时,它认为
with default
是参数。尝试:
set 2'X'(使用默认值(Array.initialize 3(始终为'X'))行1)
上一次建议的操作成功了!你能更新你的答案吗?我也会接受。我不知道列表中的
。我不知道该怎么做,但尝试一下:
设置2'X'(默认设置(fromList['X','X','X'])行1)
或者类似的东西。看起来简单多了。
    row1NextState =
        set 2 'X' (withDefault (Array.initialize 3 (always ‘X’)) row1)