[GHC] #12863: Associated data families don't use superclasses when deriving instances
GHC
ghc-devs at haskell.org
Tue Nov 22 10:19:11 UTC 2016
#12863: Associated data families don't use superclasses when deriving instances
-------------------------------------+-------------------------------------
Reporter: Iceland_jack | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 8.0.1
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):
This is just what I'd expect.
The `deriving( Functor )` clause is trying to infer a suitable context
`???` for
{{{
instance ??? => Functor (TotalMap (Identity key))
}}}
Let's call this "deriving context inference" (DCI).
To do that it needs `Functor (TotalMap key)`. But DCI insists on a simple
context with a class applied to type variables, otherwise it could infer
stupid context like `Num (Tree a)`. So it insists on being able to
simplify `Functor (TotalMap key)` and it can't.
It's true that `Key key` is also OK for `???`, since `Functor (TotalMap
key)` is a superclass, but DCI will never guess that. Apart from anything
else it might be too restrictive.
Now I think you are pointing out that DCI for an ''associated'' data type
could include the context of the parent instance declaration. It would
add a bit more code and complexity (to the compiler and the user manual).
And it might be much more restrictive than necessary. E.g.
{{{
instance (Key key) => Key (Identity key) where
data TotalMap (Identity key) val = Id val deriving( Functor )
}}}
I suppose we ''could'' specify that the derived instance is
{{{
instance (Key key) => Functor (TotalMap (Identity key))
}}}
but today we'll get the superior
{{{
instance Functor (TotalMap (Identity key))
}}}
But it would be a valid alternative design.
My suggestion: use a standalone deriving clause to specify the context
yourself. As you point out, it's not hard.
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12863#comment:2>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list