In Haskell, in order to represent the literal string "\"
, one would normally write:
"\\"
However, is there a way to escape the string such that a single backslash can be written by itself without needing to be escaped? For example, I can do exactly this in C# by pre-pending @
to the string:
@"\"
Does Haskell have an equivalent?
No, see section 2.6 of Haskell Lexical Structure.
Haskell doesn't have raw strings, heredocs or triple strings. Sorry. The only fanciness you get is this:
"ab\
\cd"
=>
"abcd"
White space between line-ending and -beginning slashes is ignored. This is useful, for example, if you want to emit some inline HTML that is properly indented in the Haskell source, but not overly indented in the output. (Not that I'd advocate doing complicated HTML output this way.)
There is a nice library (raw-strings-qq) which gives you QuasiQouter
import Text.RawString.QQ
multiline :: String
multiline = [r|<HTML>
<HEAD>
<TITLE>Auto-generated html formated source</TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1252">
</HEAD>
<BODY LINK="800080" BGCOLOR="#ffffff">
<P> </P>
<PRE>|]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With