[Haskell-cafe] Reverse Show instance

Daniel Fischer daniel.is.fischer at googlemail.com
Thu May 19 23:26:41 CEST 2011


On Thursday 19 May 2011 23:15:06, Andrew Coppin wrote:
> On 19/05/2011 10:11 PM, Artyom Kazak wrote:
> > And I can declare an instance for (x, y) which does NOT implies (Show
> > x):
> > 
> > instance Show (x, y) where
> > show _ = "I'm tuple! Hooray!"
> 
> Ah. So it's a feature.
> 
> Fortunately I refactored the program where this came up, so it's no
> longer an issue. I just wanted to see whether or not it was a bug.
> 
> PS. Wouldn't such an instance require FlexibleContexts or something?
>

No, the instance head is a type constructor applied to two distinct type 
variables, it's a perfectly valid H98 instance declaration.

It won't be accepted though, because there is already

instance (Show x, Show y) => Show (x,y) where ...

I think basically the only way to make GHC accept the above instance 
involves NoImplicitPrelude (but I may be wrong).



More information about the Haskell-Cafe mailing list