How can I write multiline strings in Haskell?

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

    Many times this facality is referred to as heredocs. Haskell does not have heredocs.

    However, there are several packages that use GHC's QuasiQuotes extensions to achieve this.

    Here is one I use: http://hackage.haskell.org/package/interpolatedstring-perl6-0.9.0/docs/Text-InterpolatedString-Perl6.html

    Your example would look like:

    file = [q|
    the first line
    the second line
    the third line
    |]
    

提交回复
热议问题