Opened 8 years ago

Closed 8 years ago

#3850 closed merge (fixed)

EmptyDataDecls and type context

Reported by: Paczesiowa Owned by: igloo
Priority: normal Milestone:
Component: Compiler Version: 6.12.1
Keywords: emptydatadecls Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: GHC rejects valid program Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


the following code fails to parse correctly or typecheck under 6.12.1

{-# LANGUAGE EmptyDataDecls #-}
data Show a => Foo a


    No context is allowed on a GADT-style data declaration
    (You can put a context on each contructor, though.)

it works with 6.10.

this is the reason of HList failure on 6.12.

Attachments (1)

test.hs (53 bytes) - added by Paczesiowa 8 years ago.

Download all attachments as: .zip

Change History (7)

Changed 8 years ago by Paczesiowa

Attachment: test.hs added

comment:1 Changed 8 years ago by simonpj

Why do you want this? It's utterly useless. Contexts on data declarations are a mis-feature of Haskell, and are especially useless when there are no constructors. Can't you just delete it?


comment:2 Changed 8 years ago by Paczesiowa

I don't have anything to do with this, maybe you should ask Oleg about such definition for labels. I just wanted to fix HList (it fails to compile with 6.12) and I've discovered, that 6.12 works different than 6.10 and also reports really misleading error message. So, I'm not interested in making this usage work like in 6.10, but there should be a better error message and some info in docs, that the behavior changed.

Oleg's code:

comment:3 Changed 8 years ago by guest

I believe contexts on data declarations might not be totally useless, even if there are no constructors. The HList code in question had the following declaration

data HNat x => Label x ns desc -- labels are exclusively type-level entities

The context HNat is asserted not because we want to use any of HNat's methods. Rather, the constraint HNat was asserted as a kind predicate -- to show to the user that the type variable x is of a kind natural numbers, so to speak. Therefore, the type (Label HZero Foo Foo) is the correct instance of label. On the other hand, the type (Label Bool Foo Foo) is not a correct instance and will be flagged as such by the compiler.


comment:4 Changed 8 years ago by simonpj

What makes you think that GHC will reject the type (Label Bool Foo Foo)? I don't think it will.

The only effect of a context on a data decl is that a use of the constructor, either in pattern matching or in an expression, gives rise to that constraint. That's all.

So the constraint is no more than a comment. I suggest you use a comment!

I'm really want a proper kind system, though. It's silly that we can't give the kind of Label. But contexts are not the way to do it.


comment:5 Changed 8 years ago by simonpj

Owner: set to igloo
Type: bugmerge

OK well I still think it's stupid, but I accept that it's a needless change in behaviour from 6.10, so I'll make 6.12 accept the declaration just as 6.10 did. That way you won't have to change HList.

Mon Feb  8 16:37:51 GMT 2010                      
  * Fix Trac #3850
  This patch simply avoids a needless difference in behaviour from 
  6.10, and one that happens to affect HList. See Note [Stupid theta].

Please merge to 6.12 branch.


comment:6 Changed 8 years ago by igloo

Resolution: fixed
Status: newclosed


Note: See TracTickets for help on using tickets.