th-format: Template Haskell based support for format strings

[ bsd3, data, library ] [ Propose Tags ]

This package implements a Template Haskell quasi quoter for format strings.

[Skip to Readme]
Versions [faq],,,
Dependencies base (>=4.7 && <5), Earley (>= && <0.14), haskell-src-meta (>= && <0.9), template-haskell (>= && <2.15), text (>= && <1.3) [details]
License BSD-3-Clause
Copyright 2017-2019 Moritz Clasmeier
Author Moritz Clasmeier
Category Data
Home page
Bug tracker
Source repo head: git clone
Uploaded by mtesseract at 2019-11-15T20:44:03Z
Distributions NixOS:
Downloads 1564 total (10 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Hackage Matrix CI
Docs available [build log]
Last success reported on 2019-11-15 [all 1 reports]


[Index] [Quick Jump]


Maintainer's Corner

For package maintainers and hackage trustees

Readme for th-format-

[back to package description]

th-format Hackage version Stackage version Build Status


This is th-format, a Haskell package implementing support for format strings using Template Haskell quasi quoters. It requires the GHC extension QuasiQuotes to be enabled. Parsing is implemented using Earley.

This package is BSD3 licensed.


Using th-format, you can use naive variable interpolation instead of verbosely concatenating strings manually. Thus, instead of

putStrLn $ "Client \"" ++ show client ++ "\" has requested resource \"" ++ show resource ++ "\" at date " ++ show date ++ "."

one can directly write:

putStrLn $ [fmt|Client "$client" has requested resource "$resource" at date $date|]

There are currently two supported ways of interpolation:

  1. Simple interpolation, as in [fmt|Variable foo contains $foo|].
  2. Expression interpolation, as in [fmt|The toggle is ${if toggle then ("on" :: Text) else "off"}|]