DeriveGeneric gets a wrong infix constructor associativity when type is declared in a different module
For example, the operators
infixr 5, but their
Generic.Rep say otherwise (
'InfixI 'LeftAssociative 9) (see code block below for an illustration).
My most plausible hypothesis for the cause is that
DeriveGeneric does not take precedence into account when the type lives in a different module from its
Generic instance. Indeed,
 have their
Generic instances derived in
GHC.Generic, whereas things looks fine if we declare a type with an infix constructor and derive
Generic in the same module.
ghci> :kind! (Rep [Int]) (Rep [Int]) :: * -> * = D1 ('MetaData "" "GHC.Types" "ghc-prim" 'False) (C1 ('MetaCons "" 'PrefixI 'False) U1 :+: C1 ('MetaCons ":" ('InfixI 'LeftAssociative 9) 'False) ...) ghci> :kind! (Rep (NonEmpty Int)) (Rep (NonEmpty Int)) :: * -> * = D1 ('MetaData "NonEmpty" "GHC.Base" "base" 'False) (C1 ('MetaCons ":|" ('InfixI 'LeftAssociative 9) 'False) ...)
These two examples should read
'InfixI 'RightAssociative 5.
- GHC version used: 8.6, 8.8