Difficulties around inferring exotic contexts
In the following code:
{-# LANGUAGE TypeFamilies, FlexibleContexts, UndecidableInstances #-}
class C r
type family F r
newtype Foo r = Foo r
instance (C (F r), Eq r) => Eq (Foo r)
newtype Bar r = Bar (Foo r) deriving (Eq)
GHC produces the error
No instance for (C (F r))
arising from the 'deriving' clause of a data type declaration
Possible fix:
use a standalone 'deriving instance' declaration,
so you can specify the instance context yourself
When deriving the instance for (Eq (Bar r))
If I enable StandaloneDeriving
, I am able to derive the instance: deriving instance (Eq (Foo r)) => Eq (Bar r)
The docs indicate that this is exactly the instance that should be generated by GND for
newtype T v1..vn = MkT (t vk+1..vn) deriving (C t1..tj)
,
where my code uses the following parameters:
T = Bar
v1 = r
n = 1
MkT = Bar
t = Foo r
k= 1
C = Eq
j = 0
and all of the conditions enumerated in the docs seem to be met. Furthermore, Bar
seems to fit squarely into the format of data T1
in section 7.5.1 of the same documentation, which indicates it should not need StandaloneDeriving
. It seems that the type family constraint on the Eq
instance for Foo
is causing the problem, but it's not clear why I'm forced to write a standalone instance that is identical to the one that should be generated by GND.
Trac metadata
Trac field | Value |
---|---|
Version | 7.10.2 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Compiler |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |