The problem is that there is not enough context to determine which instance of Add
to use, and hence the type of the result cannot be determined. Since ghc doesn't know which types to use, it reports the most generic problem, there's no Show
instance for a generic SumTy a b
:
No instance for (Show (SumTy a0 b0))
arising from a use of `show'
Possible fix: add an instance declaration for (Show (SumTy a0 b0))
In the second argument of `($)', namely `show (add 1 1)'
In the expression: print $ show (add 1 1)
In an equation for `main': main = print $ show (add 1 1)
The suggested "Possible fix" isn't what is required here, though. What you need is to specify the types of the arguments to add
, so that the instance to use can be determined, and thus the result type:
*TyFun> show (add (1 :: Int) (1 :: Int))
"2"
*TyFun> show (add (1 :: Integer) (1 :: Integer))
"2"
*TyFun> show (add (1 :: Integer) (1 :: Double))
"2.0"
*TyFun> show (add (1 :: Integer) (1 :: Float))
<interactive>:7:1:
No instance for (Show (SumTy Integer Float))
arising from a use of `show'
Possible fix:
add an instance declaration for (Show (SumTy Integer Float))
In the expression: show (add (1 :: Integer) (1 :: Float))
In an equation for `it':
it = show (add (1 :: Integer) (1 :: Float))
<interactive>:7:7:
No instance for (Add Integer Float) arising from a use of `add'
Possible fix: add an instance declaration for (Add Integer Float)
In the first argument of `show', namely
`(add (1 :: Integer) (1 :: Float))'
In the expression: show (add (1 :: Integer) (1 :: Float))
In an equation for `it':
it = show (add (1 :: Integer) (1 :: Float))