Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new hardline behavior changes multiline strings #189

Closed
vmchale opened this issue Aug 1, 2020 · 4 comments
Closed

new hardline behavior changes multiline strings #189

vmchale opened this issue Aug 1, 2020 · 4 comments

Comments

@vmchale
Copy link
Contributor

vmchale commented Aug 1, 2020

With prettyprinter (due to #139 I think) <1.7 it prints

vanessa@vanessa-desktop ~/programming/haskell/done/dickinson 🌸 cat lib/cowsay.dck -E
%-$
$
(:def cowsay$
  (:lambda txt text$
    '''$
    $
    ${txt}$
    ------$
          \   ^__^$
           \  (oo)\_______$
              (__)\       )\/\$
                  ||----w |$
                  ||     ||$
    '''))$

With the new behavior, this is:

%-$
$
(:def cowsay$
  (:lambda txt text$
    '''$
$
    ${txt}$
    ------$
          \   ^__^$
           \  (oo)\_______$
              (__)\       )\/\$
                  ||----w |$
                  ||     ||$
    '''))

Unfortunately there's no way to say "keep indentation that would otherwise be blank after newline" - and getting rid of the empty whitespace changes the meaning of the whole string (I think something similar might happen in Dhall?).

Perhaps a new combinator?

@sjakobi
Copy link
Collaborator

sjakobi commented Aug 1, 2020

Oh! Could you share the code that produces this output?

@sjakobi
Copy link
Collaborator

sjakobi commented Aug 1, 2020

Ah, I think I get it, and the culprit is indeed #139. I hadn't expected that the whitespace produced by indenting empty lines could be significant, and I still kind of feel that it shouldn't be.

In Dhall, this leading whitespace doesn't matter, and in fact the dhall pretty-printer actively ensures that indented empty lines of multi-line strings don't result in trailing whitespace:

https://github.com/dhall-lang/dhall-haskell/blob/2662044b3ceaccc31898a67ab53cc05b382118cd/dhall/src/Dhall/Pretty/Internal.hs#L1393-L1397

In your case, you can simply annotate each line of the multi-line string. The annotation then prevents the layouter from perceiving the line as empty, so it will always produce the space characters.

@vmchale
Copy link
Contributor Author

vmchale commented Aug 3, 2020

In Dhall, this leading whitespace doesn't matter, and in fact the dhall pretty-printer actively ensures that indented empty lines of multi-line strings don't result in trailing whitespace:

That might be the thing to here!

And thanks for the pointer w.r.t. annotations :)

@vmchale vmchale closed this as completed Aug 3, 2020
@sjakobi
Copy link
Collaborator

sjakobi commented Aug 3, 2020

You're welcome, @vmchale! :)

I'm somewhat wondering whether this is something that we should document in the haddocks… I'm not sure where though.

Let's maybe see whether this is an issue that more people will stumble upon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants