Reputation: 3
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.
Upvotes: 0
Views: 450
Reputation: 36385
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
Upvotes: 1