What is wrong with the following instance of the haskell typeclass instance?

data II = I Int Int deriving (Show)
instance II Show where
  show I a b = show (a+b)

showt.hs: 3: 2: show' is not a (visible) method of classII '

+3
source share
1 answer

The class name should appear before the type in the instance declaration. You also need to delete the offer deriving, as you are providing your own instance instead of using the one that was automatically received. You also need to add parentheses around one argument to show, otherwise it looks like 3 arguments to the parser.

data II = I Int Int
instance Show II where
    show (I a b) = show (a+b)
+8
source

All Articles