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

#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/T...] 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

#12580: Eagerly simplify inherently-coherent instances -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler (Type | Version: 8.0.1 checker) | 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 goldfire): For the instance to be accepted, don't we also need (`constraintI` implies `constraintC`)? Perhaps that's what you mean by the constraints being identical. To rephrase your proposal, you wish solving for `C` to pretend that `IncoherentInstances` is in effect, reducing to `constraintC`/`constraintI` even when another given is in scope. This seems plausible at first glance. Do you have a full concrete example of where this would change behavior? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12580#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC