#5406: Template Haskell: Reification of type family instances
---------------------------------+------------------------------------------
    Reporter:  reinerp           |        Owner:              
        Type:  feature request   |       Status:  new         
    Priority:  normal            |    Milestone:              
   Component:  Template Haskell  |      Version:  7.0.4       
    Keywords:                    |     Testcase:              
   Blockedby:                    |   Difficulty:              
          Os:  Unknown/Multiple  |     Blocking:              
Architecture:  Unknown/Multiple  |      Failure:  None/Unknown
---------------------------------+------------------------------------------
Changes (by simonpj):

 * cc: alfonso.acosta@…, illissius@…, Ashley, Yakeley, SamAnklesaria
 (added)


Comment:

 Reasonable request -- but what ''should'' the API be?   Currently for
 classes we have
 {{{
 classInstances :: Name -> [Type] -> Q [ClassInstance]
 data Info = ClassI Dec ClassInstance | ...
 data ClassInstance = ...a record of stuff about the instance...
 }}}
 So doing `(reify c)` gets you all the instance of class `c` in its
 `ClassI`; or you can look up an instance more selectively with
 `classInstances` (which returns all instances matching the type template).

 Thoughts:
  * I like your idea of returning the instances as a Dec, rather than as a
 new data type like `ClassInstance`.
  * I'm slightly dubious about always returning all the instances of a
 class in its `ClassI` constructor; there could be a lot of them.  But only
 slightly.

 Here's a proposal
  * Generalise `classInstances` thus:
 {{{
 reifyInstances :: Name -> [Type] -> Q [Dec]
 }}}
   this would replace `classInstances` (or at least `classInstances` could
 be implemented in terms of it).

  * `reifyInstances` would work on a `Name` of a class, type family, or
 data family, returning a `Dec` that was a `InstanceD`, `DataInstD`,
 `NewtypeInstD`, or `TySynInstD` respectively.

  * For uniformity with `ClassI`, I suppose that `TyConI` should have a
 `[Dec]` that was the list of instances in the case of data or type
 families.  But it's less nice, because most `TyCon`s are not families, so
 the list would always be empty for them.  I suppose we could split
 `TyConI` thus:
 {{{
 data Info = ... | TyConI Dec
                 | FamilyConI Dec [Dec]
             ...
 }}}
  where family type constructors come ot as `FamilyTyConI`.

 I'm ccing other people who were involved in #1835.

 Simon

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/5406#comment:1>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler

_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to