12 Metaprogramming in Haskell

This chapter covers

  • Haskell features to support deriving type class instances automatically
  • Exploiting a generic representation for any data type to write data-type-generic code
  • Generating code at compile time with Template Haskell

When we write code in Haskell, we call it programming. When we write code that generates or processes other code on our behalf, we call it metaprogramming, or generative programming. With metaprogramming techniques, we usually automate repetitive boilerplate code, which is too dull to write manually. This leads to boosting developer productivity. Sometimes, there is a price to pay—such code can be quite hard to write and maintain.

In Haskell, we have the full spectrum of metaprogramming ...

Get Haskell in Depth now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.