{"slug": "template-haskell-quotations-guide", "title": "Template haskell quotations guide", "summary": "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`.", "body_md": "Because of [Working towards a more stable Template Haskell](https://informal.codes/posts/stabilising-th/#producing-syntax-using-quotes-stable-but-unpopular-type-a), 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`\n\nquotes. (e.g. `Pat`\n\n, `Con`\n\n, `Name`\n\n, `Expr`\n\n) Is there a resource that says for example\n\nin `[d| $n :: Int|]`\n\n, `n :: Q Name`\n\nor something? (I’m not actually sure what the expected type of `n`\n\nis )\n\nI’ve been using AI + autocomplete to muddle through, but I’d like reliable documentation.\n\nAppreciated examples would be something that fills in boxes like the following:\n\n```\n[| newtype $(newtype' :: Q Name) = $(con' :: Q ?) $(type' :: Q ?) deriving anyclass ($(n :: ?))|]\n```\n\nIt’s sadly not possible to splice a value of type `Name`\n\n. See: [ghc/#24922](https://gitlab.haskell.org/ghc/ghc/-/issues/24922)\n\nSometimes you can splice a `Name`\n\nby turning it into a `Exp`\n\n, `Pat`\n\nor `Type`\n\n.\n\nSplicing is documented here: [6.13. Template Haskell — Glasgow Haskell Compiler 9.15.20260306 User's Guide](https://ghc.gitlab.haskell.org/ghc/doc/users_guide/exts/template_haskell.html#:~:text=A%20top,Dec)\n\nSo, the only allowed types (currently) are `Q Exp`\n\n, `Q Pat`\n\n, `Q Type`\n\nand `Q [Dec]`\n\n.\n\nType errors can be a helpful way if finding out what is expected. If you put something of type `Q Exp`\n\nwhere you need a `Q Pat`\n\n, then the error should tell you.\n\nSorry 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?\n\nIt 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).", "url": "https://wpnews.pro/news/template-haskell-quotations-guide", "canonical_source": "https://discourse.haskell.org/t/template-haskell-quotations-guide/14185#post_4", "published_at": "2026-06-02 17:49:57+00:00", "updated_at": "2026-06-02 20:21:07.217857+00:00", "lang": "en", "topics": ["ai-tools"], "entities": ["Template Haskell", "GHC", "Glasgow Haskell Compiler"], "alternates": {"html": "https://wpnews.pro/news/template-haskell-quotations-guide", "markdown": "https://wpnews.pro/news/template-haskell-quotations-guide.md", "text": "https://wpnews.pro/news/template-haskell-quotations-guide.txt", "jsonld": "https://wpnews.pro/news/template-haskell-quotations-guide.jsonld"}}