
#13733: Simplify constraints on RULES LHS -------------------------------------+------------------------------------- Reporter: nomeata | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.3 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 nomeata): Oh, yes, the library author can! But someone downstream does not have the ability to change the {{{ instance Eq [a] where x == y = rhs }}} to the above format. Similarly if they want to write {{{ data T = … deriving Show }}} In both cases I would consider consider your approach an work-around that, well, works around the fact that an instance method does not have a Haskell-adressable name. So what am I proposing?… now, before I propose something, let me phrase clearly what I want to achieve: **I want to write rules that apply to an instance method.** (Your approach does not quite achieve that. What it does achieve is that I no longer want to address instance methods, as I can now adress `eqT`, which works fine in many cases. But this does not work if the instance declaration is out of my control.) There may be several ways of achieving this goal. One way would be: **Simplify constraints of rules with the current instances and apply class-op rules on the LHS of rules.** This way, the user’s rule {{{ forall (xs :: [Integer]). xs == xs = True }}} gets desugared to {{{ forall (xs_a1Hd :: [Integer]). == @ [Integer] ($fEq[] @ Integer $fEqInteger) xs_a1Hd xs_a1Hd = GHC.Types.True }}} (compare that with the rule above, which has a pattern variable $dEq_a1Jv for the `Eq [Integer]` dictionary), and then gentle simplification (including class-op) on the left turns this into {{{ forall (xs_a1Hd :: [Integer]). GHC.Classes.$fEq[]_$c== @Integer $fEqInteger xs_a1Hd xs_a1Hd = GHC.Types.True }}} which – how convenient – is precisely the code we want to match, in the form the simplifier puts it. This machinery should allow the rule author to address any concrete instance method, in his module or an imported module, by using the class method with a sufficiently precise type. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13733#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler