
#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 songzh): Replying to [comment:5 goldfire]:
Yes -- TH struggles a bit with instance lookup and such. Implementing new querying features shouldn't be hard though, if you can suggest an API.
Why do you need fancy querying capabilities for your use case? Where does `reifyInstances` fail for you? As for type synonyms, you can check out the `th-expand-syns` package. `th-desugar` also does (limited) type family expansion (among other, larger features).
Replying to [comment:5 goldfire]:
Yes -- TH struggles a bit with instance lookup and such. Implementing new querying features shouldn't be hard though, if you can suggest an API.
Why do you need fancy querying capabilities for your use case? Where does `reifyInstances` fail for you? As for type synonyms, you can check out the `th-expand-syns` package. `th-desugar` also does (limited) type family expansion (among other, larger features).
Hi Richard I tried to implement a prototype of this top down deriving scheme with standalone deriving. The project is on https://github.com/HaskellZhangSong/TopdownDerive However, I have 3 problems about it. 1. It forces me to use `KindSignatures`, `ConstraintKind` and other extension which should not be needed.(please see `TopDownDeriveTest.hs` file) 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). 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. Thanks Song -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10607#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler