[Haskell-cafe] Template Haskell vs Rewrite Rules?

Michael Sloan mgsloan at gmail.com
Thu Apr 19 14:19:53 CEST 2012

You're in luck!  This is something I've wanted to implement before in
the past, and your email reminded me.  While pretty awful, it could be
used for doing some interesting value-interception instrumentation in
Haskell.  Recently I've been messing with TH a lot, so this initial
implementation was rather straightforward.



Note: Relatively untested implementation, let me know if you find any problems!

It only does this transformation to direct function application,
unfortunately.  In order to properly overload apply for infix
operators, you'll need to be able to resolve fixities at compile time.
 This could be done by using the code in
and using the fixity information yielded by TH's "reify".  Someone
aught to have done this before, but I haven't seen it.

Handling the applications involved in do-notation, comprehensions,
enumerations, and anything else that's such direct syntax sugar would
also be a bit of work (but could be very useful for other TH
quasiquoting stuff!).

You might also be interested in this:


Hope that helps!

-Michael Sloan

On Wed, Apr 18, 2012 at 9:49 AM, Ismael Figueroa Palet
<ifigueroap at gmail.com> wrote:
> I'm working on getting annotated versions of all instances of a function of
> a typeclass, and was wondering what are the relation/differences between
> Template Haskell and the Rewrite Rules section. Of course this is specific
> to GHC.
> Another question, in Racket, primitive function application is denoted
> #%app. And using macros I can re-export #%app to be a different function f,
> so a program:
> (g a) is rewritten into (f g a)
> is there a way to do the same thing using TH or Rewrite Rules?
> Thanks
> --
> Ismael
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

More information about the Haskell-Cafe mailing list