Eagerly simplify inherently-coherent instances
https://downloads.haskell.org/~ghc/8.0.1/docs/html/libraries/ghc-8.0.1/src/TysPrim.html explains that
~ 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
class constraintC => C a1 a2 ... instance constraintI => C a1 a2 ...
a2, etc., are type variables,
C is inherently coherent if both of the following hold:
Chas no methods whatsoever.
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.
|Component||Compiler (Type checker)|