[Haskell-cafe] Pretty Printing Libraries with an Emphasis on Consistency
Oliver Charles
ollie at ocharles.org.uk
Sat Oct 11 09:52:18 UTC 2014
Hi all,
It seems that all of the pretty printing libraries on Hackage at the moment
have an emphasis on being compact, but not necessarily consistent. By
consistent, I mean that similar blocks of code are indented in the same
fashion, even when not strictly necessary.
Take for example, the start of "Pretty Printing with Lazy Dequeues". Here,
the example is:
if True
then if True then True else True
else
if False
then False
else False
I call this inconsistent, because the two sides of the top-level if have
been formatted under different rules. A consistent formatting of this would
be:
if True
then
if True
then True
else True
else
if False
then False
else False
The above can obviously be reached if you *always* format `if` in this
style, but that's not what I'm after. If it's possible to format both sides
on one-line, then that should be preferred. So an equally desirable output
(that meets my "consistency" requirement) is:
if True
then if True then True else True
else if True then True else True
It doesn't seem that there is a library on Hackage that lets one express
such a pretty printer. It seems that a pretty printer of this nature would
need to have some sort of backtracking ability - I can imagine trying to
print both sides of the if statement on one-line, and if this fails, try
printing *both* on multiple lines.
Curious to hear what people have to say on this matter,
- ocharles
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20141011/b6530510/attachment.html>
More information about the Haskell-Cafe
mailing list