[GHC] #4815: Instance constraints should be used when deriving on associated data types
GHC
ghc-devs at haskell.org
Tue Oct 25 08:10:55 UTC 2016
#4815: Instance constraints should be used when deriving on associated data types
-------------------------------------+-------------------------------------
Reporter: batterseapower | Owner:
Type: feature request | Status: new
Priority: low | Milestone:
Component: Compiler | Version: 6.12.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 simonpj):
I think it's more than just #11008.
The question of this ticket is just "what context should GHC infer for a
'deriving' clause." But the ticket concerns the specific case of a `data
instance` inside a `class` instance decl, thus:
{{{
instance <context> => C (T a b) where
data D (T a b) = D1 a | D2 b
}}}
Now arguably, whether or not the `deriving Eq` part ''needs'' `<context>`
it would do no harm to add it, so we get the derived instance
{{{
instance <context> => Eq (DT a b) where
(==) = <blah>
}}}
(where `DT` is the representation data type for `D (T a b)`). The point
is that `<context>` might help satisfy the `Eq` constraints arising from
`<blah>`.
Max argues that `<context>` must already be satisfied (because the class
instance holds). But that's not really true
{{{
f x y = D1 x == D2 y
}}}
Here we need equality on `DT` but we don't need `C (T a b)`. So
`<context>` might be over-constraining.
So I'm unconvinced that this is worth the bother.
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/4815#comment:17>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list