th-format: Template Haskell based support for format strings

This is a package candidate release! Here you can preview how this package release will appear once published to the main package index (which can be accomplished via the 'maintain' link below). Please note that once a package has been published to the main package index it cannot be undone! Please consult the package uploading documentation for more information.

[maintain] [Publish]

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


[Skip to Readme]

Properties

Versions 0.1.0.0, 0.1.0.0, 0.1.1.0, 0.1.2.0, 0.1.3.0
Change log None available
Dependencies base (>=4.7 && <5), Earley, haskell-src-meta, template-haskell, text [details]
License BSD-3-Clause
Copyright 2017-2018 Moritz Clasmeier
Author Moritz Clasmeier
Maintainer mtesseract@silverratio.net
Category Data
Home page https://github.com/mtesseract/th-format#readme
Bug tracker https://github.com/mtesseract/th-format/issues
Source repo head: git clone https://github.com/mtesseract/th-format
Uploaded by mtesseract at 2018-03-20T22:47:08Z

Modules

[Index]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


Readme for th-format-0.1.0.0

[back to package description]

th-format Hackage version Stackage version Build Status

About

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.

Examples

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"}|]