How can I write multiline strings in Haskell?

后端 未结 6 864
南旧
南旧 2021-02-02 05:10

Let\'s say I have this string literal with line breaks:

file :: String
file = \"the first line\\nthe second line\\nthe third line\"

Is there an

6条回答
  •  青春惊慌失措
    2021-02-02 05:54

    You can write multiline strings like so

    x = "This is some text which we escape \
          \   and unescape to keep writing"
    

    Which prints as

    "This is some text which we escape   and unescape to keep writing"
    

    If you want this to print as two lines

    x = "This is some text which we escape \n\
          \   and unescape to keep writing"
    

    Which prints as

    This is some text which we escape
        and unescape to keep writing
    

提交回复
热议问题