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

#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

#9687: Missing Typeable instances for built-in types -------------------------------------+------------------------------------- Reporter: selinger | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.3 Resolution: | Keywords: Operating System: | Architecture: Unknown/Multiple Unknown/Multiple | Difficulty: Unknown Type of failure: | Blocked By: None/Unknown | Related Tickets: Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Comment (by simonpj): What if you say {{{ 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) }}} using standalone deriving? Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9687#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9687: Missing Typeable instances for built-in types -------------------------------------+------------------------------------- Reporter: selinger | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.3 Resolution: | Keywords: Operating System: | Architecture: Unknown/Multiple Unknown/Multiple | Difficulty: Unknown Type of failure: | Blocked By: None/Unknown | Related Tickets: Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Comment (by selinger): Simon, what you suggest seems like the logical solution, but doesn't currently work. Test.hs: {{{ import Data.Typeable 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) }}} And here's what happens when you compile it: {{{ selinger@firefly-virtual:/tmp$ ghc --version The Glorious Glasgow Haskell Compilation System, version 7.8.3 selinger@firefly-virtual:/tmp$ ghc Test [1 of 1] Compiling Main ( Test.hs, Test.o ) Test.hs:1:1: Typeable instances can only be derived; replace the following instance: 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) -- Defined at Test.hs:3:10 selinger@firefly-virtual:/tmp$ }}} By the way, this bug doesn't just apply in the case of built-in types such as 8-tuples. It would also apply to any type that is defined by a library, where the library author neglected to derive a Typeable instance. It seems impossible for user code to provide the requisite instances. -- Peter -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9687#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9687: Missing Typeable instances for built-in types -------------------------------------+------------------------------------- Reporter: selinger | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.3 Resolution: | Keywords: Operating System: | Architecture: Unknown/Multiple Unknown/Multiple | Difficulty: Unknown Type of failure: | Blocked By: None/Unknown | Related Tickets: Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Comment (by goldfire): `Typeable` instances must be for unapplied type constructors. This works: {{{ deriving instance Typeable (,,,,,,,) }}} But, I agree with the original post that GHC should export `Typeable` instances for ''all'' tuples. Otherwise, code like my line above risks having an instance collision. Incoherent instances avoids this problem, but that's an annoying burden if users have to worry about it. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9687#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9687: Missing Typeable instances for built-in types -------------------------------------+------------------------------------- Reporter: selinger | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.3 Resolution: | Keywords: Operating System: | Architecture: Unknown/Multiple Unknown/Multiple | Difficulty: Unknown Type of failure: | Blocked By: None/Unknown | Related Tickets: Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Comment (by simonpj): The error message is very confusing though. It would be good if someone felt like improving it. Yes I agree about instances. Should be a question of adding `DeriveAutoTypeable` (or whatever it's called) to the module that defines all the tuple types. Would someone like to do that? Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9687#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9687: Missing Typeable instances for built-in types -------------------------------------+------------------------------------- Reporter: selinger | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.3 Resolution: | Keywords: Operating System: | Architecture: Unknown/Multiple Unknown/Multiple | Difficulty: Unknown Type of failure: | Blocked By: None/Unknown | Related Tickets: Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Comment (by selinger): Great, I confirm that this works: {{{ {-# LANGUAGE StandaloneDeriving #-} {-# LANGUAGE DeriveDataTypeable #-} import Data.Typeable deriving instance Typeable (,,,,,,,) }}} Solves my problem in the short term. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9687#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9687: Missing Typeable instances for built-in types -------------------------------------+------------------------------------- Reporter: selinger | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.3 Resolution: | Keywords: Operating System: | Architecture: Unknown/Multiple Unknown/Multiple | Difficulty: Unknown Type of failure: | Blocked By: None/Unknown | Related Tickets: Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Comment (by dreixel): Replying to [comment:4 simonpj]:
Yes I agree about instances. Should be a question of adding `DeriveAutoTypeable` (or whatever it's called) to the module that defines all the tuple types. Would someone like to do that?
`AutoDeriveTypeable`. But, if I recall correctly, we've decided against that in the past because: 1) It increased the object file size and/or compilation time significantly (though maybe we were also deriving `Data` and `Generic`); 2) Very few people would make use of it; 3) They could always use `StandaloneDeriving`. But perhaps it's time to revisit that decision. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9687#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9687: Missing Typeable instances for built-in types -------------------------------------+------------------------------------- Reporter: selinger | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.3 Resolution: | Keywords: Operating System: | Architecture: Unknown/Multiple Unknown/Multiple | Difficulty: Unknown Type of failure: | Blocked By: None/Unknown | Related Tickets: Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Comment (by simonpj): A `Typeable` instance for, say, `(,,,,,)` should not increase object file size much, should it? Are you perhaps thinking of `Data` or something like that? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9687#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9687: Missing Typeable instances for built-in types -------------------------------------+------------------------------------- Reporter: selinger | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.3 Resolution: | Keywords: Operating System: | Architecture: Unknown/Multiple Unknown/Multiple | Difficulty: Unknown Type of failure: | Blocked By: None/Unknown | Related Tickets: Test Case: | deriving/should_fail/T9687 | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Changes (by simonpj): * testcase: => deriving/should_fail/T9687 Comment: I'll improve the error message for a hand-written `Typeable` instance anyway. Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9687#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9687: Missing Typeable instances for built-in types -------------------------------------+------------------------------------- Reporter: selinger | Owner: Type: bug | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 7.8.3 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: | deriving/should_fail/T9687 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by thomie): * status: new => closed * resolution: => fixed Comment: `typeOf (1,2,3,4,5,6,7,8)` (up to 62) works in 7.10.3 and HEAD, probably as a result of #9858 ("Generate Typeable info at definition sites"). #10451 also dealt with the tuple size limitations. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9687#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC