Skip to content

Missing Typeable instances for built-in types

According to the PolyTypeable wiki, https://ghc.haskell.org/trac/ghc/wiki/GhcKinds/PolyTypeable, "Users can no longer giving manual instances of Typeable; they must be derived."

I cannot figure out how to do this for built-in types with missing Typeable instances. For example, my code requires a Typeable instance for 8-tuples. However, Typeable instances are natively only defined for 2- to 7-tuples:

Prelude> :m Data.Typeable
Prelude Data.Typeable> typeOf (1)
Integer
Prelude Data.Typeable> typeOf (1,2)
(Integer,Integer)
Prelude Data.Typeable> typeOf (1,2,3)
(Integer,Integer,Integer)
Prelude Data.Typeable> typeOf (1,2,3,4)
(Integer,Integer,Integer,Integer)
Prelude Data.Typeable> typeOf (1,2,3,4,5)
(Integer,Integer,Integer,Integer,Integer)
Prelude Data.Typeable> typeOf (1,2,3,4,5,6)
(Integer,Integer,Integer,Integer,Integer,Integer)
Prelude Data.Typeable> typeOf (1,2,3,4,5,6,7)
(Integer,Integer,Integer,Integer,Integer,Integer,Integer)
Prelude Data.Typeable> typeOf (1,2,3,4,5,6,7,8)

<interactive>:10:1:
    No instance for (Typeable (,,,,,,,)) arising from a use of ‘typeOf’
    In the expression: typeOf (1, 2, 3, 4, 5, 6, 7, 8)
    In an equation for ‘it’: it = typeOf (1, 2, 3, 4, 5, 6, 7, 8)
Prelude Data.Typeable>

Since my code does not define the type of 8-tuples (it is defined in the Prelude, or even in the compiler), it is not possible to "derive" a Typeable instance for it. With the old Typeable class, I could just define it myself:

instance (Typeable a, Typeable b, Typeable c, Typeable d, Typeable e, Typeable f, Typeable g, Typeable h) => Typeable (a,b,c,d,e,f,g,h) where
  typeOf _ = typerep
    where
      typerep = mkTyCon3 "GHC" "Tuple" "(,,,,,,,)" `mkTyConApp` [ typeOf (undefined :: a), typeOf (undefined :: b), typeOf (undefined :: c), typeOf (undefined :: d), typeOf (undefined :: e), typeOf (undefined :: f), typeOf (undefined :: g), typeOf (undefined :: h) ]

With the new Typeable class, I am completely stumped. How can I "derive" an instance for a pre-defined type?

I think this is a bug. Typeable instances should be pre-defined for all pre-defined types, including //n//-tuples for all //n//.

Trac metadata
Trac field Value
Version 7.8.3
Type Bug
TypeOfFailure OtherFailure
Priority normal
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