[GHC] #9334: Implement "instance chains"

GHC ghc-devs at haskell.org
Sun Aug 10 23:09:52 UTC 2014


#9334: Implement "instance chains"
-------------------------------------+-------------------------------------
              Reporter:  diatchki    |            Owner:  diatchki
                  Type:  feature     |           Status:  new
  request                            |        Milestone:
              Priority:  normal      |          Version:  7.9
             Component:  Compiler    |         Keywords:
  (Type checker)                     |     Architecture:  Unknown/Multiple
            Resolution:              |       Difficulty:  Unknown
      Operating System:              |       Blocked By:
  Unknown/Multiple                   |  Related Tickets:
       Type of failure:              |
  None/Unknown                       |
             Test Case:              |
              Blocking:              |
Differential Revisions:              |
-------------------------------------+-------------------------------------

Comment (by AntC):

 Replying to [comment:4 diatchki]:
 > Interestingly, even in my simple version, instance chains are a bit more
 expressive, because of the explicit ordering of instances.  So we can
 write things like this:
 > {{{
 > instance C Int a    where ...
 > else     C a   Int  where ...
 > }}}
 > I am not sure how common cases like these are, but it is worth noting.

 I suspect they're rare, but yes they are problematic.
 Can't you always resolve this today with an instance at the intersect?
 {{{
  instance C Int Int  where ...
  instance C Int a    where ...
  instance C a   Int  where ...
 }}}
 (The `where`'s body for `C Int Int` would be the same as `C Int a` to
 match Ivor's example.)
 Probably for this to work all three instances must be in the same module.
 The main awkwardness is that GHC still sees the partially overlapping two
 instances and gets upset (wants `XIncoherentInstances`). If only it could
 realise there is no incoherence!

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


More information about the ghc-tickets mailing list