Template Haskell reification of instances

Simon Peyton-Jones simonpj at microsoft.com
Fri Aug 13 14:01:44 EDT 2010


Dear TH users

In Template Haskell, it's not currently possible to say "give me all the instances of this class"; it's a long-standing feature request.

Sam Anklesaria has come up with a design and implemented it. Before committing to it, I want to check that other Template Haskell users are happy with the design. 

You can find the details here:
	http://hackage.haskell.org/trac/ghc/ticket/1835

But a summary of the design appears below.  If you have a stake in Template Haskell, pls RSVP by adding a comment to the ticket.

Thanks

Simon


================
Proposed design

    * Extending the Quasi monad to have

      class (Monad m, Functor m) => Quasi m where
        ...
        qReify :: Name -> m Info
        qIsClassInstance :: Name -> [Type] -> m Bool

      isClassInstance :: Name -> [Type] -> Q Bool
      isClassInstance n ts = Q (qIsClassInstance n ts)

    * Extending the info you get back when reifying a Class, by adding its instances:

      data Dec = ...
        | ClassI Dec [([TyVarBndr],Cxt,[Type])]

Some random thoughts

    * In principle, I suppose that isClassInstance isn't really necessary: 
      you could reify the class and search the list yourself. 
      But I can see that it's convenient.

    * Currently isClassInstance returns True if any instances match, 
      even if they overlap etc. Might you want to know more?


More information about the Glasgow-haskell-users mailing list