null-skill
null-skill

Reputation: 39

Extracting values from Haskell type synonyms

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?

Upvotes: 3

Views: 151

Answers (1)

Federico Sawady
Federico Sawady

Reputation: 900

If you replace this DomsPlayer with its definition

type DomsPlayer = Hand -> Board -> (Domino,End)

playTurn :: (Hand -> Board -> (Domino,End)) -> (Int, Hand, Board)

you will see that playTurn recieves only one parameter, not two.

I don't know what you are trying to do, but clearly you will need to recieve Hand and Board as separate params:

playTurn :: Hand -> Board -> ... -> (Int, Hand, Board)

And I don't know, maybe also pass a function of type DomsPlayer too, and apply it to those separate arguments.

But that is your error.

Upvotes: 0

Related Questions