cd /news/ai-tools/template-haskell-quotations-guide · home topics ai-tools article
[ARTICLE · art-19300] src=discourse.haskell.org pub= topic=ai-tools verified=true sentiment=· neutral

Template haskell quotations guide

A Haskell developer seeking reliable documentation for Template Haskell quotation types reports difficulty determining expected types for splices within quotes, such as whether a splice requires `Q Name` or another type. The GHC user guide confirms that only `Q Exp`, `Q Pat`, `Q Type`, and `Q [Dec]` are currently allowed splice types, with a feature request open to expand support for additional types like `Name`.

read2 min publishedJun 2, 2026

Because of Working towards a more stable Template Haskell, I’m trying to use quotes whenever possible in my template Haskell. Unfortunately, I don’t know what types are expected where in the template haskell

quotes. (e.g. Pat

, Con

, Name

, Expr

) Is there a resource that says for example

in [d| $n :: Int|]

, n :: Q Name

or something? (I’m not actually sure what the expected type of n

is )

I’ve been using AI + autocomplete to muddle through, but I’d like reliable documentation.

Appreciated examples would be something that fills in boxes like the following:

[| newtype $(newtype' :: Q Name) = $(con' :: Q ?) $(type' :: Q ?) deriving anyclass ($(n :: ?))|]

It’s sadly not possible to splice a value of type Name

. See: ghc/#24922

Sometimes you can splice a Name

by turning it into a Exp

, Pat

or Type

.

Splicing is documented here: 6.13. Template Haskell — Glasgow Haskell Compiler 9.15.20260306 User's Guide

So, the only allowed types (currently) are Q Exp

, Q Pat

, Q Type

and Q [Dec]

.

Type errors can be a helpful way if finding out what is expected. If you put something of type Q Exp

where you need a Q Pat

, then the error should tell you.

Sorry for the late response. Thank you, I thought that there were more, as the article led me to believe that quotations could do most of the things that manually creating the AST did. Are there any plans for adding to the supported spices? One day, will I be able to do the type of quotation that I put in my top level post?

It can do most but sadly not all. I would love to extend it to support your use-case. It’s quite an important one! I am vaguely planning to work on this at some point, but my time to work on TH is quite limited sadly (I do it all in my free time).

── more in #ai-tools 4 stories · sorted by recency
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
Live at https://your-agent.zahid.host
Get free account → Pricing
from €0/mo · no card required
LIVE [news/template-haskell-quo…] indexed:0 read:2min 2026-06-02 ·