-
Notifications
You must be signed in to change notification settings - Fork 31
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
Adding emptyLine document #26
Comments
I'm not sure what the best approach to this is right now sorry. On the surface it seems that it may be challenging to get what you want as it sort of breaks the modularity here of things like |
While we wait for haskell/pretty#26, we patch the output. Not a pretty fix, but it'll work for us. This closes #3.
Me too. I am hitting the same problem, trailing spaces produced by The current situation is bad since it forces the programmer into non-compositionality when using the pretty printing framework. By this I mean that |
Empty lines are useful to separate blocks in printed programs, but unless I'm getting the API wrong, currently only way to produce a empty newline is to use
text ""
.empty
doesn't work, because it's unit of$$
and$+$
.The problem with
text ""
is that when combined withnest
, it produces trailing white space. For example, this:Generates this:
I propose implementing an
emptyLine
document, like this:This works fine, for example, this program:
prints this:
Which is not bad, but now it's printing an extra new line at the end.
So I think there are two problems:
This use of
NilAbove
is actually invalidating some internal invariants. Even though I couldn't manage to produce a broken example with this new doc, in the code it's mentioned that:Which this change clearly invalidates.
We need to make some changes in some of the combinators to handle extra newline printed in the case of
text "blah" $+$ emptyLine
. I think it's printed because of this invalidated invariant.So at this point I'm hoping to get some comments and ideas. Do you think this is a correct way of doing this? Is there any other way to produce new lines without producing trailing white spaces?
Also, some help with changing internals would be great.
Thanks.
UPDATE: I just tried this program:
And it produced this:
It's good to see that next line after the
blah
is not indented. Last indented empty line should be fixed when we remove that line.UPDATE 2: Here's a broken example:
Output:
An
emptyLine
should never be indented, that's the whole point of it. Documentation sometimes mention "height" and "width", maybe we should be able to say "emptyLine has height 1 and width 0".The text was updated successfully, but these errors were encountered: