我正在学习Haskell。
以下代码未编译
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
错误:无法将预期类型Nim与实际类型“a”匹配。 'a'是由player :: a - >的输入签名约束的刚性类型变量。播放器。
任何帮助都将不胜感激。
答案 0 :(得分:1)
Class和Instance声明需要包含其包含函数的间距:
class Position a where
score :: a -> Int
player :: a -> Player
instance Position Nim where
score a = count a
player a = turn a