2016-05-16 192 views
0

我正在學習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 

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.

任何幫助,將不勝感激。

回答

1

的類和實例聲明需要間距爲他們的職能包括:

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

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

現在編譯OK。謝謝你的幫助。 – user6340505

+0

非常感謝 – user6340505

相關問題