[Haskell-cafe] Typeclass Show Question
yasu at yasuaki.com
Sun Nov 30 23:55:18 UTC 2014
When I launch GHCI with the option -XGADTs and load the following program,
f = \x y -> (1, x,y)
data S a b where
S :: (Num a, Num b) => a -> b -> S a b
I encounter this dialog:
*Main> S 1 1
No instance for (Show (S a0 b0))
arising from a use of `print'
Possible fix: add an instance declaration for (Show (S a0 b0))
In a stmt of an interactive GHCi command: print it
I tried to follow the recommendation but still could not figure out how.
For example, after adding:
instance Show (S a b) where
show (S x y) = show(x)
I still get:
Could not deduce (Show a) arising from a use of `show'
from the context (Num a, Num b)
bound by a pattern with constructor
S :: forall a b. (Num a, Num b) => a -> b -> S a b,
in an equation for `show'
add (Show a) to the context of
the data constructor `S'
or the instance declaration
In the expression: show (x)
In an equation for `show': show (S x y) = show (x)
In the instance declaration for `Show (S a b)'
Failed, modules loaded: none.
What should I do to show S 1 1 ?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe