Typist is a library for interpolation. It uses type-level strings (Symbols) for template. It uses UnconsSynbol type family which is added in GHC-9.2, so you need GHC version 9.2 or higher to use it.
Core functionality is in Typist.Internal.Format:
- Type family
Formatwhich transformsSymbolto function which renders final string Argnewtype overText.Lazy.Builderwhich carries name of parameter and it's position in string on type-level (for perfomance goods)- Type class
Interpolatewhich renders final string on term level
An example of wrapping it (and also ready to use interface) is located in Typist.TextShow:
Unquotednewtype for interpolation strings without\"#=set operator Example (more examples can be found intest/Test):
question = fmt @"Hello, #{name}, do you like #{dish}?" $
(#name #= Unquoted "Mike") .
(#dish #= Unquoted "pasta")Performance is comparable with bare concatenation with <>. Benches can be found at test/Bench
To run benchmark use
$ cabal bench --benchmark-options '--svg results_cpu.svg'