I'm using the prettyprinter library to prettyprint foo(bar, baz), and when the margin is too narrow, I'd like it to look like:
foo(
bar,
baz)
How do I do that?
My best attempts so far:
> import Prettyprinter
> import Prettyprinter.Util
> let commas = punctuate comma
-- 'sep' and 'nest' seem to go well together, but the result lacks the linebreak
> putDocW 10 ("foo" <> parens (nest 2 (sep (commas ["bar", "baz"]))))
foo(bar,
baz)
-- Using 'line'' inside 'nest' almost does the trick
> putDocW 10 ("foo" <> parens (nest 2 (line' <> sep (commas ["bar", "baz"]))))
foo(
bar,
baz)
-- Except 'line'' doesn't seem "mempty" enough
> putDocW 20 ("foo" <> parens (nest 2 (line' <> sep (commas ["bar", "baz"]))))
foo(
bar, baz)
I thought what I want is line' because of the mention of mempty:
line'is likeline, but behaves likememptyif the line break is undone bygroup(instead ofspace).
But perhaps I misunderstand what "undone by group" does.
It seems that none of the other ones (line, softline and softline') give better results.