
#10607: Auto derive from top to bottom -------------------------------------+------------------------------------- Reporter: songzh | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.11 Resolution: | Keywords: deriving, | typeclass, auto Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): -------------------------------------+------------------------------------- Comment (by goldfire): Replying to [comment:6 songzh]:
1. It forces me to use `KindSignatures`, `ConstraintKind` and other
extension which should not be needed.(please see `TopDownDeriveTest.hs` file) Fair enough. But, in truth, you ''might'' need these extensions, depending on the definitions of types you are deriving for. One way forward here is to allow Template Haskell to turn on some extensions just within a splice, instead of specifying them at the top of a file. (This actually shouldn't be hard, once #10820 is complete.)
2. For type synonym, I want to do it without using TypeSynonymInstance,
but I am not sure how to get the arity of a type constructor. For example: `type T a = (a,a,a,a,a)` I need to generate (Eq a , Eq b, Eq c ,Eq d, Eq e) => (a,b,c,d,e). However, the type synonym can be eta reduced, what should do to handle this case? I'm not sure what the problem is here. Are you worried about deriving, say, `Functor`, for which the eta reduction is necessary? But your example actually cannot be eta-reduced, because the variable `a` is used multiple times in the RHS. So I'm not sure what you're getting at on this one.
3. When I derive some instances that based on Generic class like Binary
or FromJSON it gives me a type error:
{{{ Could not deduce (G.Generic a) arising from a use of `binary-0.7.6.1:Data.Binary.Class.$gdmget' from the context (B.Binary a) bound by the instance declaration }}}
while I think `deriving instance (Binary a ,Binary b) => Binary (A a b)`
should work fine. Why do I have to write `deriving instance (B.Binary a, G.Generic a) => (B.Binary (B a))`? And could you give me some suggestions to solve it. I'm a little lost here. What's the code being type-checked? What's `A`? What's `B`? Does the error happen both with and without TH? Or only when using TH? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10607#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler