Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#10000 closed bug (duplicate)

Derived DataKinds Typeable instance collision leads to SafeHaskell violation

Reported by: shachaf Owned by:
Priority: normal Milestone:
Component: Compiler Version: 7.8.4
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


The derived Typeable instances for a kind (with DataKinds) is equal to the instance of a type with the same name:

λ> data T = T
λ> typeRep (Proxy :: Proxy T) == typeRep (Proxy :: Proxy 'T)

This can be used to violate SafeHaskell easily:

{-# LANGUAGE AutoDeriveTypeable, DataKinds, TypeFamilies, RankNTypes #-}

module Unsafe where

import Data.Typeable

data T = T

data family F p

newtype instance F (Proxy  T) = ID (forall a. a -> a)
newtype instance F (Proxy 'T) = UC (forall a b. a -> b)

uc :: a -> b
uc = case cast (ID id) of Just (UC f) -> f
$ ghc -XSafe Unsafe.hs -e "uc 'a' :: Int"

Change History (4)

comment:1 Changed 4 years ago by monoidal

Duplicate of #9858?

comment:2 Changed 4 years ago by shachaf

Resolution: duplicate
Status: newclosed

Looks like it. And I was so pleased about finding it, too. :-(

comment:3 Changed 4 years ago by simonpj

We've hit 10,000 tickets!

comment:4 Changed 4 years ago by hvr

Too bad this turned out to be a duplicate, I was hoping for #10000 to be a more memorable ticket :-)

Note: See TracTickets for help on using tickets.