Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell "show is applied to too many type arguments"

Tags:

haskell

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?

like image 878
matio2matio Avatar asked Dec 10 '22 12:12

matio2matio


1 Answers

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
like image 141
Josh Lee Avatar answered Dec 24 '22 20:12

Josh Lee