[ghc-steering-committee] Proposal #569: multiline string literals; Rec: accept

Eric Seidel eric at seidel.io
Wed Dec 27 19:23:43 UTC 2023


Dear Committee,

Brandon Chinn has proposed[1] adding multi-line strings to Haskell. Most languages these days support multi-line strings, even Java has them as of Java 17 (which coincidentally is a strong inspiration for Brandon's proposal). Yet in Haskell we have to resort to tricks like `unlines`  or quasiquoters.

Brandon's proposal adds support for triple-quote delimited multi-line strings, e.g.

```
adtParseJSON =
  """
  \\v -> case v of
    Aeson.Null -> pure PrintStyleInherit
    Aeson.String "" -> pure PrintStyleInherit
    _ -> PrintStyleOverride <$> Aeson.parseJSON v
  """
```

The rules are largely inspired by Java's text blocks[2] proposal, which I've also read and find very pragmatic. Honestly, I encourage the Committee to read the Java proposal as well. Haskell innovates in many areas of language design, but the lexical structure of strings feels like an area where we should conserve our innovation tokens. Brandon's proposal does a great job here of starting from an established baseline and adapting it to Haskell's idiosyncrasies. 

One point I would draw the Committee's attention to is the handling of characters on the opening line[3]. My only concern with this proposal is that omitting the opening line from the prefix calculation can lead to some counterintuitive behavior. For example

```
s = """ foo
        bar
    """
```

would be parsed as `" foo\nbar"`. I'm on the fence about whether we should try to be more prescriptive here, or just expect that Haskeller's will learn to avoid this corner case. I think it's probably fine.

On balance I think we should accept the proposal.

Thanks!
Eric

[1]: https://github.com/ghc-proposals/ghc-proposals/pull/569
[2]: https://openjdk.org/jeps/378
[3]: https://github.com/brandonchinn178/ghc-proposals/blob/multiline-strings/proposals/0569-multiline-strings.rst#33ignore-leading-characters


More information about the ghc-steering-committee mailing list