How can I write multiline strings in Haskell?

后端 未结 6 765
南旧
南旧 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:32

    I don't believe that Haskell has an easy way to do this without resorting to quasiquoting or something else. However you can mostly get what you want by using the unlines function like below. However this will result in a newline after your last line, which you may or may not care about.

    file :: String
    file = unlines [
        "the first line",
        "the second line",
        "the third line"
        ]
    

提交回复
热议问题