sol / interpolate

String interpolation for Haskell done right!
MIT License
31 stars 5 forks source link

wishlist: quoter that allows me to use backslashes in a simple manner #11

Open reuleaux opened 6 years ago

reuleaux commented 6 years ago

this is for the wishlist: In general I like your interpolate package , its parameter feature for example: [i| ... #{param} ... ], or the possibility to use String and Text types.

There are times however when I have to resort to the simpler (String only) Text.RawString.QQ (pkg raw-strings-qq), which does not offer parameters, when I am assembling some latex code snippets for example, I use

   [r|
       \documentclass[a4paper,oneside]{report}
       \usepackage{foobar}
    |]

for backslash serves as an escape in your i quoter, and I don't want to write double backslashes with your i quoter

 [i|
       \\documentclass[a4paper,oneside]{report}
       \\usepackage{foobar}
    |]

using just a single backslash with the r quoter, I can cut & past my latex snippets for example.

I wish your Interpolate package would offer a second quoter, that does NOT treat the backslash any special, but otherwise offers all of your package's advantages. thanks.

safinaskar commented 5 years ago

Special behavior of backslashes is not even documented in https://hackage.haskell.org/package/interpolate-0.2.0/docs/Data-String-Interpolate.html . Please, at least document it

thomasjm commented 5 years ago

Just to add an edge case here that bit me: these two values have the same result in the i quoter:

> putStrLn [i|print("hi")|]
print("hi")
> putStrLn [i|print(\"hi\")|]
print("hi")

I was not expecting this, since I was trying to produce a string that actually has literal backslashes in it. It turns out using two produces that result:

> putStrLn [i|print(\\"hi\\")|]
print(\"hi\")

Very confusing :)