Skip to content

Unexpected constraint when using ExistentialQuantification

Hello! Consider this simple code:

data Elem t = Typeable t => Elem Int

tst1 :: forall a. Elem a -> TypeRep
tst1 (Elem _) = typeRep (Proxy :: Proxy a)

It works and it should work. Elem is created only to be sure that if we've got a value of type Elem t we don't have to check that t is Typeable. <offtopic> By the way, exystential newtypes would be so awesome in GHC! </offtopic>

And now a strange thing. If we create another function:

tst2 :: forall a. Elem a -> TypeRep
tst2 _ = typeRep (Proxy :: Proxy a)

GHC throws error that there is no Typeable a constraint. The only difference between tst1 and tst2 is different pattern binding.

Trac metadata
Trac field Value
Version 8.0.1
Type Bug
TypeOfFailure OtherFailure
Priority high
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information