[GHC] #11999: expressing injectivity on functional dependencies gives orphan instances warnings

GHC ghc-devs at haskell.org
Wed May 4 11:47:52 UTC 2016


#11999: expressing injectivity on functional dependencies gives orphan instances
warnings
-------------------------------------+-------------------------------------
        Reporter:  dredozubov        |                Owner:
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:
       Component:  Compiler          |              Version:  7.10.3
      Resolution:                    |             Keywords:
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by rahulmutt):

 > Note [When exactly is an instance decl an orphan?]
 > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 >   (see MkIface.instanceToIfaceInst, which implements this)
 > Roughly speaking, an instance is an orphan if its head (after the =>)
 > mentions nothing defined in this module.
 >
 > Functional dependencies complicate the situation though. Consider
 >
 >   module M where { class C a b | a -> b }
 >
 > and suppose we are compiling module X:
 >
 >   module X where
 >         import M
 >         data T = ...
 >         instance C Int T where ...
 >
 > This instance is an orphan, because when compiling a third module Y we
 > might get a constraint (C Int v), and we'd want to improve v to T.  So
 > we must make sure X's instances are loaded, even if we do not directly
 > use anything from X.

 This part of the note explains why your example would be considered an
 orphan instance. Otherwise you can define instances that may not be "seen"
 as intended.

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


More information about the ghc-tickets mailing list