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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With