
#14190: Typeable imposes seemingly redundant constraints on polykinded instances -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.4.1 Component: Compiler | Version: 8.2.1 (Type checker) | Keywords: | Operating System: Unknown/Multiple TypeableReflection | Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- To derive `Data` for `Const`, we need {{{#!hs deriving instance (Typeable k, Data a, Typeable (b :: k)) => Data (Const a b) }}} Where's that `Typeable k` constraint come from? It turns out that for reasons I haven't looked into, we can only obtain `Typeable (Const a (b :: k))` if we have `Typeable k`; `(Typeable a, Typeable b)` is insufficient. Is there a reason for that? Annoyingly, we can actually ''get'' that: {{{#!hs weGotThat :: forall k (a :: k). Typeable a :- Typeable k weGotThat = Sub $ withTypeable (typeRepKind (typeRep :: TypeRep a)) Dict }}} But of course that doesn't help us. Could we use `UndecidableSuperClasses` to work around this problem? I think we likely can, although I'm concerned about the performance implications: {{{#!hs class (Typeable a, Typeable' k) => Typeable' (a :: k) instance (Typeable a, Typeable' k) => Typeable' (a :: k) withTypeable' :: forall k (a :: k) r. TypeRep a -> (Typeable' a => r) -> r withTypeable' tr f = withTypeable tr $ withTypeable (typeRepKind (typeRep @a)) f }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14190 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler