0
votes

I am learning Haskell.

the following code is not compiling

data Player = Max  | Min
  deriving (Show,Eq)

class Position a where
score :: a -> Int
player :: a -> Player


data Nim = Nim { turn :: Player, count :: Int}

instance Position Nim where
score a = count a
player a = turn a

error: Could not match expected type Nim with actual type 'a'. 'a' is a rigid type variable bound by the input signature for player :: a -> Player.

Any help would be appreciated.

1

1 Answers

1
votes

The Class and Instance declarations need spacing for their included functions:

class Position a where
  score :: a -> Int
  player :: a -> Player

instance Position Nim where
  score a = count a
  player a = turn a