
#15151: Better Interaction Between Specialization and GND -------------------------------------+------------------------------------- Reporter: andrewthad | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Research | needed Component: Compiler | Version: 8.4.2 Resolution: | Keywords: deriving Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * status: infoneeded => new * milestone: 8.6.1 => Research needed Comment: OK. I think I'm inclined to agree with Simon here that isn't at all simple to achieve. GHC doesn't track whether an instance was derived or not (let alone whether it was GND'd or not), and moreover, it's questionable that we'd even want to do this. After all, why should a GND'd instance receive special privileges? If I defined this instance manually: {{{#!hs instance Eq PersonId where (==) = coerce @Int @PersonId (==) }}} Then why shouldn't GHC be able to recognize that that instance has the same representation the `Eq Int` instance? A similar problem arises when you try to `coerce` from a `Map Int ()` to a `Map PersonId ()`. The nominal role on `Map`'s first type argument prevents this from typechecking, which is rather unsatisfying, since the `Ord PersonId` instance has the same representation as the `Ord Int` instance. Again, folks have asked if there is a way we could carve out an exception here to allow this to typecheck if `Ord PersonId` was GND'd, but I have similar reservations about that idea as I do the one proposed in this ticket. In short, it feels like there ought to be a more general guiding principle here to determine whether two instance dictionaries are representationally equivalent. I'm not sure what that would be, though. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15151#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler