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

Oliver Charles ollie at ocharles.org.uk
Sat Oct 11 16:00:39 UTC 2014


Yes, hindent is exponential in its pretty printing and that's exactly the
program I'm trying to speed up ;) To be specific, hindent has `sandbox`
which runs a printer and then lets me make decisions on what the resulting
state might be. I'm curious if there are other approaches.

- ocharles

On Sat, Oct 11, 2014 at 12:01 PM, Alan & Kim Zimmerman <alan.zimm at gmail.com>
 wrote:

> Have you looked at hindent?
> On 11 Oct 2014 11:52 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/587f9ced/attachment.html>


More information about the Haskell-Cafe mailing list