[GHC] #12580: Eagerly simplify inherently-coherent instances

GHC ghc-devs at haskell.org
Thu Sep 8 04:08:11 UTC 2016


#12580: Eagerly simplify inherently-coherent instances
-------------------------------------+-------------------------------------
           Reporter:  dfeuer         |             Owner:
               Type:  feature        |            Status:  new
  request                            |
           Priority:  normal         |         Milestone:
          Component:  Compiler       |           Version:  8.0.1
  (Type checker)                     |
           Keywords:                 |  Operating System:  Unknown/Multiple
       Architecture:                 |   Type of failure:  None/Unknown
  Unknown/Multiple                   |
          Test Case:                 |        Blocked By:
           Blocking:                 |   Related Tickets:
Differential Rev(s):                 |         Wiki Page:
-------------------------------------+-------------------------------------
 [https://downloads.haskell.org/~ghc/8.0.1/docs/html/libraries/ghc-8.0.1/src/TysPrim.html]
 explains that `~~` and `~` are "inherently coherent", so GHC can reduce
 them immediately to their constraints. It seems to me that certain user-
 written classes can also be seen to be inherently coherent in this
 fashion. Specifically, given

 {{{#!hs
 class constraintC => C a1 a2 ...
 instance constraintI => C a1 a2 ...
 }}}

 where `a1`, `a2`, etc., are type variables, `C` is inherently coherent if
 both of the following hold:

 1. `C` has no methods whatsoever.

 2. `constraintC` entails `constraintI` (so the constraints are effectively
 identical).

 I believe in these cases GHC can and probably should reduce `C a1 a2`
 immediately to `constraintC`. Condition (2) is more general that we really
 need; in realistic cases, the constraints will be identical up to alpha
 renaming because most people don't write obfuscated code.

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


More information about the ghc-tickets mailing list