[GHC] #9443: Regression from 7.6.3 to 7.8.3: could not coerce because argument "has role Nominal"
GHC
ghc-devs at haskell.org
Thu Aug 14 12:36:00 UTC 2014
#9443: Regression from 7.6.3 to 7.8.3: could not coerce because argument "has role
Nominal"
-------------------------------------+-------------------------------------
Reporter: bernalex | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 7.8.3
Resolution: | Keywords:
Operating System: | Architecture: x86_64 (amd64)
Unknown/Multiple | Difficulty: Unknown
Type of failure: GHC | Blocked By:
rejects valid program | Related Tickets:
Test Case: |
Blocking: |
Differential Revisions: |
-------------------------------------+-------------------------------------
Comment (by goldfire):
I don't think this is a bug, but I suppose I could be convinced otherwise.
Consider this:
{{{#!hs
class C a where
meth :: D a => a -> a
}}}
Note that the constraint on `meth` is ''not'' `C a`, but some other class
`D a`. If we wish to derive an instance of `C` via GND, the derived
instance will use the exact same implementation of `meth` as does the
original instance. BUT, the newtype (say, `Year a`) may have a
''different'' instance for `D` compared to the representation type
(`Integer`). So, reusing the old implementation would be bogus. That's why
class parameters default to have nominal roles.
Of course, if we knew that the `D` instances were in fact the same, then
the derivation makes good sense. But GHC doesn't track "instance equality"
(which could just mean that one instance is the GND of the other). In the
case presented here, the instance equality is guaranteed, as we're
performing the GND to make the instances equal. However, detecting this,
in general, is hard, and this seems like enough of a corner case to let it
go unfixed.
Does that explain it?
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9443#comment:4>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list