[GHC] #12814: Should GND infer an instance context when deriving method-free classes?
GHC
ghc-devs at haskell.org
Tue Nov 8 10:07:40 UTC 2016
#12814: Should GND infer an instance context when deriving method-free classes?
-------------------------------------+-------------------------------------
Reporter: RyanGlScott | Owner:
Type: bug | Status: new
Priority: normal | Milestone: 8.2.1
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: #11369, #12810 | Differential Rev(s):
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by simonpj):
Replying to [comment:2 goldfire]:
> Just infer the class constraint based on the constraints that arise when
type-checking the generated definition.
I agree with this; and it's precisely what Ryan's patch does.
`mkNewTypeEqn` generates the constraints that are necessary to satisfy the
instance decl; they are then simplified, perhaps to nothing at all. We
are going to generate
{{{
instance ?? => C (N a) where
...type instances...
op = coerce (op :: rep-ty)
}}}
So for each method (if any) we need
* `C rep_ty` so that we have the underlying `op`
* `op_ty[rep_ty] ~R op_ty[N a]` to for the coercion of the `op`
If there are no methods we don't need any of those constraints. Ryan's
notes above show that the result may perhaps not be what you want, but if
not, just use a standalone deriving and specify the instance context.
So I vote for this patch!
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12814#comment:4>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list