Thursday, April 7, 2016

Multi-line strings in Haskell

When we have a very long string in Haskell, how can we break it into a multi-line one without calling any function on it to concatenate it back? It turns out that Haskell has special syntax for that. To do it we use a backslash at the end and beginning of a string:

 let longLine = "long_line1___\
  \long_line2___\
  \long_line3"

-- => "long_line1___long_line2___long_line3"




Sublime Text 3 doesn't highlight it properly. Nonetheless, it's valid and compiles.

No comments :

Post a Comment