Opened 10 years ago

Closed 10 years ago

Last modified 2 years ago

#810 closed bug (fixed)

GHC complains about missing instance in conjunction with GADTs

Reported by: wolfgang@… Owned by: simonpj
Priority: normal Milestone: 6.8.1
Component: Compiler Version: 6.4.1
Keywords: Cc:
Operating System: Linux Architecture: x86
Type of failure: Test Case: gadt20
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


I wanted to do something like that:

data Pair :: (* -> *) -> * where
    Pair :: a b -> b -> Pair a

data Sel :: * -> * where
    A :: Sel Bool
    B :: Sel Integer

showSnd :: Pair Sel -> String
showSnd (Pair A bool)    = show bool
showSnd (Pair B integer) = show integer

However, GHC 6.4.1 with -fglasgow-exts complains in the second last and last line that there is no instance for (Show b). But it is clear that bool :: Bool and integer :: Integer and that therefore bool and integer are showable. In addition, Chris Kuklewicz said the following:

I cut and pasted your code into ghci-6.4.2 with -fglasgow-exts and there was no

error. And I can (print (showSnd (Pair A True)) and (print (showSnd (Pair B 8))) but when I try to compile it with ghc-6.4.2 it complains about the Show instance. I find this deeply wierd, and it seems like a bug.

Change History (9)

comment:1 Changed 10 years ago by simonpj

Seems all right with GHC 6.4.2 to me. I dn't nkow what Chris thinks doesn't work.

Mind you, type classes and GADTs don't work togeher properly, still, so it's good luck that this one is ok.


comment:2 Changed 10 years ago by wolfgang@…

Hmm, I have to admit that I don't really understand your last sentence. Do you mean that one needs to be in luck in order to not have problems with my example code?

comment:3 Changed 10 years ago by guest

simonpj wrote:

Seems all right with GHC 6.4.2 to me. I dn't nkow what Chris thinks doesn't work.

What Chris means is that the example code is accepted by GHCi 6.4.2 (which is the right behavior, in my opinion) but it's not accepted by the ordinary GHC compiler of the same version.

comment:4 Changed 10 years ago by simonpj

The odd thing is that it works with 6.4.2 (batch, not GHCi). Maybe Chris can try again?

My comment about luck is simply that GHC is badly broken when it comes to a mixture of type classes and GADTs. It's something high on my priority list, but for you can't rely on it to behave well, or even predictably.

comment:5 Changed 10 years ago by simonpj

  • Milestone set to 6.8
  • Owner set to simonpj

comment:6 Changed 10 years ago by igloo

  • Test Case set to gadt20

This case seems fine in 6.6, but I assume the bug is being kept open for other, similar issues?

comment:7 Changed 10 years ago by simonpj

  • Resolution set to fixed
  • Status changed from new to closed

I think this is actually ok in 6.6, and in any case I'm fixing the type-class interaction, and we have a test case to remind us if it goes bad on us.

So I'm closing this bug.


comment:8 Changed 8 years ago by igloo

  • Milestone changed from 6.8 branch to 6.8.1

comment:9 Changed 2 years ago by Ian Lynagh <igloo@…>

In 5a6c7d62ae6fe2f264b8734f91bd75c58c56600e/ghc:

Add test gadt20 for trac #810 (GHC fails to find GADT instances)
Note: See TracTickets for help on using tickets.