Haskell“show适用于太多类型的参数”

时间:2010-11-10 18:18:15

标签: haskell

我正在尝试在haskell中复制UNIX程序wc。为了使这更容易,我创建了一个类型:

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)'

有谁知道为什么?

1 个答案:

答案 0 :(得分:14)

类型WCResult不接受任何参数 - 您将类型构造函数与 data 构造函数混淆,后者确实接受了参数:

instance Show WCResult where
    show (WCResult x y) = show x ++ " " ++ y
相关问题