str implements multiline strings with interpolation.
Interpolating a value into the string is done by
and interpolating anything with instance Show is
$:<Show expression>$. Due to pretty deep limitations, the parser
is not able to properly deduce associtivity of infix operators,
so use lots and lots of parenthesis.
Repetitive patterns can be made with # symbol:
#<var> in <list>: <interpolated string> (|<interpolated string>)#
Where (|<interpolated string>) denotes optional separator for the elements.
Multiline indentation is handled by aligning on smallest un-empty line after the first. Neither pattern matching nor nested #-patterns are supported, however, see example below.
Normal '\\n' style escaping of special characters is intentionally not supported. Please use $endline$ or $n$ style instead.
As an example, let's plot set of vectors with gnuplot:
plotVecs :: [(String,[Double])] -> String plotVecs vs = [$str| ## Plot multiple vectors plot #(n,_) in vs:
-with lines lw 5 title $:n$ |, # #d in map snd vs:$singleVec d$$endline$e$endline$# |] where singleVec n = [$str|#(e,i) in zip n [1..]: $:i$ $:e$|$endline$#|]