matio2matio
matio2matio

Reputation: 303

Haskell "show is applied to too many type arguments"

I am trying to replicate the UNIX program wc in haskell. To make this easier I have created a type:

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

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

When I try and run this program I get

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

Does anyone know why?

Upvotes: 4

Views: 2740

Answers (1)

Josh Lee
Josh Lee

Reputation: 177574

The type WCResult doesn’t take any parameters — you’re confusing the type constructor with the data constructor, which does take arguments:

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

Upvotes: 14

Related Questions