I'm writing a Dominoes game for class and can't wrap my head around custom types. I have:
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
Trying to load this gives me the errors:
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 |
How do I retrieve the values from DomsPlayer?
DomsPlayer
is a function of two arguments (Hand
andBoard
). Your functionplayTurn
take as argument such aDomsPlayer
function and returns a triple. However, your pattern match forplayTurn
has 2 arguments (hand1
andboard1
). This does not fit together. – mschmidtHand
and aBoard
? Or do you want a(Domino, End)
too? Clearly you are defining a function, becauseDomsPlayer
is a synonym of function. – Federico Sawady