Open georgefst opened 4 years ago
Yeah. When I started using this library, I believe I found this behaviour a bit strange, too.
The documentation for group
tries to point it out though, at least if you read it closely:
(group x) tries laying out x into a single line by removing the contained line breaks; if this does not fit the page, x is laid out without any changes.
Importantly, the single-line layout also fails when the document contains a hard linebreak.
Do you think this should be made clearer, and would you possibly have a suggestion how to clarify it?
I don't think this behaviour can be easily changed, in any case. Sometimes you want to group
a document where you don't know yet whether some inner part has a hard linebreak or not. In that case the current behaviour is actually desirable.
In your case, you could possibly use softline
instead of line
.
For me, it's far from clear from that Haddock coment... But I'm sorry I don't really understand the behaviour well enough to suggest something better.
Anyway, I ended up solving my problem by going with a very different approach.
@georgefst I've tried to clarify the documentation for group
a bit in https://github.com/quchen/prettyprinter/pull/168.
Could you check whether that's better?
Thanks. That makes it a lot more obvious.
I agree that this is surprising behavior, despite the documentation mentioning it. group
is a bit tricky at times… #168 improves the docs, but you still have to read that section though in order to understand the behavior. Unfortunately, I don’t think this is easily fixed in code, so the updated documentation will have to do.
I'll leave this open for a bit, just in case someone comes up with an idea to improve the documentation on this further.
I'm not quite experienced enough with this library to confidently call this a bug, but the following behaviour certainly seems odd:
outputs:
as though the use of
hardline
has made theline
hard as well. The same result is seen with"a" <> hardline <> "b" <> line <> "c"
.