我正在爲類寫一個多米諾骨牌遊戲,無法將自己的頭包裹在自定義類型中。我有:從Haskell類型同義詞中提取值
type DomsPlayer = Hand -> Board -> (Domino,End)
...
playTurn :: DomsPlayer -> (Int, Hand, Board)
playTurn hand1 board1 = (score, hand2, board2)
where (dom, end) = simplePlayer hand1 board1
board2 = resMaybe (playDom dom board1 end)
hand2 = remove dom hand1
score = scoreBoard board2
嘗試加載這給了我的錯誤:
Dominoes.hs:43:3: error:
• Couldn't match expected type ‘(Int, Hand, Board)’ with actual type ‘Board -> (Int, b0, Board)’
• The equation(s) for ‘playTurn’ have two arguments, but its type ‘DomsPlayer -> (Int, Hand, Board)’ has only one
| 43 | playTurn hand1 board1 = (score, hand2, board2) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^...
Dominoes.hs:44:37: error:
• Couldn't match type ‘Hand -> Board -> (Domino, End)’ with ‘[Domino]’
Expected type: Hand Actual type: DomsPlayer
• Probable cause: ‘hand1’ is applied to too few arguments
In the first argument of ‘simplePlayer’, namely ‘hand1’
In the expression: simplePlayer hand1 board1
In a pattern binding: (dom, end) = simplePlayer hand1 board1
| 44 | where (dom, end) = simplePlayer hand1 board1 |
如何檢索DomsPlayer值是多少?
它看起來像DomsPlayer的定義是一個函數的類型同義詞,而不是數據類型。 – Zpalmtree
您的類型'DomsPlayer'是兩個參數('Hand'和'Board')的函數。 你的函數'playTurn'作爲一個參數,例如'DomsPlayer'函數返回一個三元組。然而,你的'playTurn'模式匹配有2個參數('hand1'和'board1')。這不適合在一起。 – mschmidt
我給了一個答案,但爲了幫助你,我想知道你在做什麼。你想收到一個'''''''和'''Board'''嗎?或者你想要一個'''(Domino,End)'''?顯然你正在定義一個函數,因爲'''DomsPlayer''是函數的同義詞。 –