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 ~~
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
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:
-
C
has no methods whatsoever. -
constraintC
entailsconstraintI
(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.
Trac metadata
Trac field | Value |
---|---|
Version | 8.0.1 |
Type | FeatureRequest |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Compiler (Type checker) |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |