[GHC] #9687: Missing Typeable instances for built-in types

GHC ghc-devs at haskell.org
Mon Oct 13 00:46:03 UTC 2014


#9687: Missing Typeable instances for built-in types
-------------------------------------+-------------------------------------
       Reporter:  selinger           |                   Owner:
           Type:  bug                |                  Status:  new
       Priority:  normal             |               Milestone:
      Component:  Compiler           |                 Version:  7.8.3
       Keywords:                     |        Operating System:
   Architecture:  Unknown/Multiple   |  Unknown/Multiple
     Difficulty:  Unknown            |         Type of failure:
     Blocked By:                     |  None/Unknown
Related Tickets:                     |               Test Case:
                                     |                Blocking:
                                     |  Differential Revisions:
-------------------------------------+-------------------------------------
 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//.

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9687>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list