[Haskell-cafe] A problem with Show
Donald Bruce Stewart
dons at cse.unsw.edu.au
Sun Aug 6 04:24:37 EDT 2006
zdenes:
> Hello,
>
> I made a simple datatype called Pair and I'd like to make it an instance of Show class. But when I try to do that I run into troubles:
>
>
> data Pair a b = Pair a b
> instance Show a b => Show (Pair a b) where show (Pair a b) = show a ++ "_" ++ show b
>
>
> In Hugs I get this error: "Haskell does not support multiple parameter classes" When I run it in ghci I get a kind error "Show is applied to too many type arguments in the instance declaration for Show (Pair a b)"
>
> Am I jsut using wrong syntax or is it not possible to do?
>
Missing some parens and a comma:
> data Pair a b = Pair a b
>
> instance (Show a, Show b) => Show (Pair a b) where
> show (Pair a b) = show a ++ "_" ++ show b
$ hugs A.hs
Main> show (Pair 'x' ())
"'x'_()"
Alternately:
> data Pair a b = Pair a b
> deriving Show
-- Don
More information about the Haskell-Cafe
mailing list