GHC doesn't add constraint when deriving
I can't remember if this was intended, but GHC cannot derive newtype Functor or derive stock Functor for WGeneric even if it knows the constraint to add (I have FlexibleInstances enabled)
import GHC.Generic
-- • Could not deduce (Functor (Rep1 f))
-- arising from the 'deriving' clause of a data type declaration
-- from the context: Functor f
-- bound by the deriving clause for ‘Functor (WGeneric f)’
-- at /home/baldur/hs/074.hs:63:5-11
-- Possible fix:
-- use a standalone 'deriving instance' declaration,
-- so you can specify the instance context yourself
newtype WGeneric f a = WGeneric (Sum (Rep1 f) f a)
deriving newtype
Functor
but either of these works
deriving newtype instance (Functor f, Functor (Rep1 f)) => Functor (WGeneric f)
deriving stock instance (Functor f, Functor (Rep1 f)) => Functor (WGeneric f)
Could GHC add the inferred Functor (Rep1 f)?
Trac metadata
| Trac field | Value |
|---|---|
| Version | 8.2.1 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture |