|
58 | 58 | -- variable and each extension. If this doesn't work (e.g. you want to |
59 | 59 | -- derive 'Eq' but have a type variable of kind @'K.Type' -> 'K.Type'@), |
60 | 60 | -- you must instead write your own declaration outside of the call to |
61 | | --- 'extensible'. |
| 61 | +-- 'extensible'. The only special case is that 'Generic' is not given |
| 62 | +-- a context. |
62 | 63 | -- * Deriving for non-regular datatypes (datatypes with recursive |
63 | 64 | -- occurrences applied to different types) doesn't work. |
64 | 65 | -- |
@@ -278,6 +279,7 @@ where |
278 | 279 | import Language.Haskell.TH as TH |
279 | 280 | import Language.Haskell.TH.Syntax |
280 | 281 | import Generics.SYB (Data, everywhere, mkT) |
| 282 | +import GHC.Generics (Generic) |
281 | 283 | import Control.Monad |
282 | 284 | import Data.Functor.Identity |
283 | 285 | import Data.Void |
@@ -630,10 +632,10 @@ makeInstances :: Config |
630 | 632 | makeInstances conf name names ext tvs (SimpleDeriv strat prds) = |
631 | 633 | pure $ map make1 prds |
632 | 634 | where |
633 | | - make1 prd = StandaloneDerivD strat' |
634 | | - (map tvPred tvs ++ map allPred names) |
635 | | - (prd `AppT` appExtTvs (ConT name) ext tvs) |
636 | | - where |
| 635 | + make1 prd = StandaloneDerivD strat' ctx (prd `AppT` ty) where |
| 636 | + ty = appExtTvs (ConT name) ext tvs |
| 637 | + ctx | prd == ConT ''Generic = [] |
| 638 | + | otherwise = (map tvPred tvs ++ map allPred names) |
637 | 639 | tvPred = AppT prd . VarT . tyvarName |
638 | 640 | allPred name' = appExtTvs (ConT bname `AppT` prd) ext tvs |
639 | 641 | where bname = applyAffix (bundleName conf) name' |
|
0 commit comments