[Haskell-cafe] Template Haskell

Rafael Almeida almeidaraf at gmail.com
Fri Mar 19 12:01:24 EDT 2010

I was reading the good old template haskell paper by Sheard and Peyton
Jones [1]. It looks like some API have changed, but things seems to be
more or less the same.

I got the printf example to run, and it is an alright example of
something to do with template haskell. You lose the ability to use a
dynamic generated string for the format, but that's not a practical
drawback (I can't think of a practical reason for using anything other
than a string literal for format anyway).

Anyhow, what is gained by the template programming in that case is
really the flexibility in the type system. You can generate the function
with the correct type on the fly, during compiling. That's nice enough,
but the article keeps saying that templates are nice for implementing
your own custom compiler optimizations. I can see that you really can do
so, but I fail to think of a good practical example where templates
would be hands down the best approach. Perhaps haskellers with more
experience have real life examples they've bumped into. So, please,
share your experience with us.

[1] http://research.microsoft.com/en-us/um/people/simonpj/papers/meta-haskell/meta-haskell.pdf

More information about the Haskell-Cafe mailing list