Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8027895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:57:20+00:00 2026-06-04T23:57:20+00:00

It seems that Template Haskell is often viewed by the Haskell community as an

  • 0

It seems that Template Haskell is often viewed by the Haskell community as an unfortunate convenience. It’s hard to put into words exactly what I have observed in this regard, but consider these few examples

  • Template Haskell listed under “The Ugly (but necessary)” in response to the question Which Haskell (GHC) extensions should users use/avoid?
  • Template Haskell considered a temporary/inferior solution in Unboxed Vectors of newtype’d values thread (libraries mailing list)
  • Yesod is often criticized for relying too much on Template Haskell (see the blog post in response to this sentiment)

I’ve seen various blog posts where people do pretty neat stuff with Template Haskell, enabling prettier syntax that simply wouldn’t be possible in regular Haskell, as well as tremendous boilerplate reduction. So why is it that Template Haskell is looked down upon in this way? What makes it undesirable? Under what circumstances should Template Haskell be avoided, and why?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T23:57:22+00:00Added an answer on June 4, 2026 at 11:57 pm

    One reason for avoiding Template Haskell is that it as a whole isn’t type-safe, at all, thus going against much of “the spirit of Haskell.” Here are some examples of this:

    • You have no control over what kind of Haskell AST a piece of TH code will generate, beyond where it will appear; you can have a value of type Exp, but you don’t know if it is an expression that represents a [Char] or a (a -> (forall b . b -> c)) or whatever. TH would be more reliable if one could express that a function may only generate expressions of a certain type, or only function declarations, or only data-constructor-matching patterns, etc.
    • You can generate expressions that don’t compile. You generated an expression that references a free variable foo that doesn’t exist? Tough luck, you’ll only see that when actually using your code generator, and only under the circumstances that trigger the generation of that particular code. It is very difficult to unit test, too.

    TH is also outright dangerous:

    • Code that runs at compile-time can do arbitrary IO, including launching missiles or stealing your credit card. You don’t want to have to look through every cabal package you ever download in search for TH exploits.
    • TH can access “module-private” functions and definitions, completely breaking encapsulation in some cases.

    Then there are some problems that make TH functions less fun to use as a library developer:

    • TH code isn’t always composable. Let’s say someone makes a generator for lenses, and more often than not, that generator will be structured in such a way that it can only be called directly by the “end-user,” and not by other TH code, by for example taking a list of type constructors to generate lenses for as the parameter. It is tricky to generate that list in code, while the user only has to write generateLenses [''Foo, ''Bar].
    • Developers don’t even know that TH code can be composed. Did you know that you can write forM_ [''Foo, ''Bar] generateLens? Q is just a monad, so you can use all of the usual functions on it. Some people don’t know this, and because of that, they create multiple overloaded versions of essentially the same functions with the same functionality, and these functions lead to a certain bloat effect. Also, most people write their generators in the Q monad even when they don’t have to, which is like writing bla :: IO Int; bla = return 3; you are giving a function more “environment” than it needs, and clients of the function are required to provide that environment as an effect of that.

    Finally, there are some things that make TH functions less fun to use as an end-user:

    • Opacity. When a TH function has type Q Dec, it can generate absolutely anything at the top-level of a module, and you have absolutely no control over what will be generated.
    • Monolithism. You can’t control how much a TH function generates unless the developer allows it; if you find a function that generates a database interface and a JSON serialization interface, you can’t say “No, I only want the database interface, thanks; I’ll roll my own JSON interface”
    • Run time. TH code takes a relatively long time to run. The code is interpreted anew every time a file is compiled, and often, a ton of packages are required by the running TH code, that have to be loaded. This slows down compile time considerably.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It seems that Django doesn't have a convention on the placement of template files.
It seems that one template from Products.Five (manage_interfaces) has a bad i18n markup, making
It seems that the card board has an undocumented filterBoard() function. I have no
It seems that c# does not support c++ like templates. For example template <class
It seems that my template is never called but the for loop works correctly.
I have a problem with class member function templates. It seems that gcc is
I have an Excel template that I use to create PDF specification sheets for
I have a WPF ListBox with a defined DataTemplate. In that template, I have
I have developed a kind of brochure website template that I base most of
I'm running Sitecore 6.5 and have a data template that has an image field

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.