[Haskell-cafe] Pretty Printing Libraries with an Emphasis on Consistency

Kyle Marek-Spartz kyle.marek.spartz at gmail.com
Sat Oct 11 14:17:06 UTC 2014


Something like this would be useful for making an hsfmt or something similar.  

Stylish-haskell does some of this, but it is rather opinionated.

–  
Kyle Marek-Spartz
  
  
  
  
  
On Oct 11, 2014, 4:52:18 AM, Oliver Charles <ollie at ocharles.org.uk> wrote:  
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

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe at haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20141011/7859219d/attachment.html>


More information about the Haskell-Cafe mailing list