Search code examples
haskellconcatenationstring-literals

Does Haskell concatenate String literals at compile time?


Does Haskell 2010 guarantee to concatenate String literals at compile time?

If I have

"This is a " ++
"very long String that " ++
"spans several lines"

does the compiler treat it as

"This is a very long String that spans several lines"

I want to keep my source lines less than 80 characters long if possible, but I don't want to introduce run-time inefficiency.


Solution

  • Use a gap—a sequence of one or more whitespace characters between backslashes:

    "This is a \
    \very long String that \
    \spans several lines"
    

    The zero-width equivalent is \&, useful for separating numeric escapes from digit characters:

    "\123\&45" == "{45"
    "\12345" == "〹"