2010-11-10 33 views
4

我想在haskell中複製UNIX程序wc。爲了更方便我已經創建了一個類型:Haskell「顯示應用於太多類型參數」

data WCResult = WCResult { 
         wordCount :: Int, 
         fileName :: String 
        } --deriving (Show) 

instance Show (WCResult x y) where 
    show (WCResult x y) = show x ++ " " ++ y 

當我嘗試和運行這個程序,我得到

wc.hs:9:15: 
`WCResult' is applied to too many type arguments 
In the instance declaration for `Show (WCResult x y)' 

有誰知道爲什麼嗎?

回答

14

類型WCResult不帶任何參數 - 你混淆了構造與數據構造函數,它確實需要的參數:

instance Show WCResult where 
    show (WCResult x y) = show x ++ " " ++ y