A simple string substitution library that supports "$"-based substitution. Substitution uses the following rules:

"$$" is an escape; it is replaced with a single "$".

"$identifier" names a substitution placeholder matching a mapping key of "identifier". "identifier" must spell a Haskell identifier. The first non-identifier character after the "$" character terminates this placeholder specification.

"${identifier}" is equivalent to "$identifier". It is required when valid identifier characters follow the placeholder but are not part of the placeholder, such as "${noun}ification".

Any other apperance of "$" in the string will result in an error being raised.

Here is an example of a simple substitution:

import qualified Data.ByteString.Lazy.Char8 as B import Text.Template context = Map.fromList . map packPair where packPair (x, y) = (B.pack x, B.pack y) helloTemplate = B.pack "Hello, $name! Want some ${fruit}s?" helloContext = context [("name", "Johan"), ("fruit", "banana")] main = B.putStrLn $ substitute helloTemplate helloContext