<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p>Hi,</p>
1. Have you seen the "prettiest printer" article here?
<p>
<a class="moz-txt-link-freetext" href="https://jyp.github.io/posts/towards-the-prettiest-printer.html">https://jyp.github.io/posts/towards-the-prettiest-printer.html</a></p>
<p>It says:</p>
<p>
<blockquote type="cite">
<p>Wadler’s design fares somewhat better. It does not suffer
from the above problem… <em>by default</em>. That is, it
lacks the capability to express that sub-documents should be
vertically aligned — compositionally.</p>
</blockquote>
...</p>
<p>
<blockquote type="cite"><br>
<ul>
<li>
<p>Objection 2: <em>Leijen’s extension of Wadler’s design
solves the issue: it provides an <code>align</code>
combinator.</em></p>
</li>
</ul>
</blockquote>
<br>
</p>
<p>A package based on (a later version of) the design in this
article is available here:</p>
<p> <a class="moz-txt-link-freetext" href="https://hackage.haskell.org/package/pretty-compact">https://hackage.haskell.org/package/pretty-compact</a></p>
<p>This claims to be more ideal ("Prettiest") than either the Hughes
("Pretty") or Wadler ("Prettier") printers. I think it uses
dynamic programming to avoid being too slow. If I understand
correctly, GHC internally uses a version of the Hughes pretty
printer, not the Wadler-Leijen one. <br>
</p>
<p><br>
</p>
<p>2. Doesn't the wl-print package already have a `nest` combinator?</p>
<p>
<a class="moz-txt-link-freetext" href="https://hackage.haskell.org/package/wl-pprint-1.2.1/docs/Text-PrettyPrint-Leijen.html">https://hackage.haskell.org/package/wl-pprint-1.2.1/docs/Text-PrettyPrint-Leijen.html</a></p>
<p>It also has the `align` combinator. If I remember correctly,
these are part of the Leijen extension to Wadler. Are these not
enough to get the behavior that you want?</p>
<p><br>
</p>
<p></p>
<p>3. Have you seen hindent? It has a module called HIndent.Pretty
that might be relevant to laying out Haskell source.<br>
</p>
Does that help?<br>
<p>-BenRI</p>
<p><br>
</p>
<div class="moz-cite-prefix">On 4/17/23 6:50 AM, Johannes Waldmann
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:f64ff1e0-6d05-84e0-94d5-26c0768712af@htwk-leipzig.de">Dear
Cafe,
<br>
<br>
I was looking for a way to pretty-print Haskell literals
<br>
(with lists, tuples, records with named and positional notation)
<br>
like this example
<br>
<br>
( Leftist
<br>
{ tree = Branch
<br>
{ left = Branch { left = Leaf, key = 4, right = Leaf }
<br>
, key = 3
<br>
, right = Leaf
<br>
}
<br>
, refs = listToFM [ ( Ref 13, [ 0 ] ), ( Ref 17, [ ] ) ]
<br>
}
<br>
, [ Any, Any ]
<br>
)
<br>
<br>
for each sub-structure, the indentation level
<br>
(for the following lines) should increase - by a _fixed_ amount.
<br>
in the above example: line break after "tree = Branch".
<br>
But (missing from this example), line break _before_
<br>
the list starts in "{ foo = [ 42 , ... ] ... }".
<br>
<br>
I found this impossible to do with wl-pprint
<br>
but perhaps I did not try hard enough.
<br>
<br>
<br>
Instead, I "invented" combinators `nest` and `skip`
<br>
and made this prototypical implementation
<br>
<a class="moz-txt-link-freetext" href="https://gitlab.imn.htwk-leipzig.de/autotool/all0/-/blob/master/todoc/src/Text/PrettyPrint/Dent.hs">https://gitlab.imn.htwk-leipzig.de/autotool/all0/-/blob/master/todoc/src/Text/PrettyPrint/Dent.hs</a>
(it has some explanatory text at the top)
<br>
see also
<a class="moz-txt-link-freetext" href="https://gitlab.imn.htwk-leipzig.de/autotool/all0/-/issues/960">https://gitlab.imn.htwk-leipzig.de/autotool/all0/-/issues/960</a>
<br>
<br>
but certainly this cannot be a new idea.
<br>
<br>
<br>
While I do like the semantics (in the context of my application),
<br>
I don't like the performance of my implementation.
<br>
What am I doing wrong?
<br>
It's just updating indentation level and current position,
<br>
this should not take any time at all?
<br>
<br>
Of course, it would be best if I don't need the implementation at
all -
<br>
if the effect could be achieved via some combinators in
<br>
established libraries (that have optimized implementation).
<br>
<br>
Any pointers appreciated.
<br>
<br>
<br>
Best regards - J.
<br>
_______________________________________________
<br>
Haskell-Cafe mailing list
<br>
To (un)subscribe, modify options or view archives go to:
<br>
<a class="moz-txt-link-freetext" href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a>
<br>
Only members subscribed via the mailman list are allowed to post.<br>
</blockquote>
</body>
</html>