Hi all,<br><br>Thanks everyone for the help.  The HughesPJ module works well for me.<br><br>Cheers,<br><br>-John<br><br><div class="gmail_quote">On Mon, Jul 6, 2009 at 3:49 AM, Chris Eidhof <span dir="ltr">&lt;<a href="mailto:chris@eidhof.nl">chris@eidhof.nl</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div><div></div><div class="h5">On 4 jul 2009, at 05:13, Alexander Dunlap wrote:<br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
On Fri, Jul 3, 2009 at 6:45 PM, John Ky&lt;<a href="mailto:newhoggy@gmail.com" target="_blank">newhoggy@gmail.com</a>&gt; wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi,<br>
<br>
Currently I&#39;m pretty printing code by building arrays of strings and calling<br>
indent.  For example:<br>
<br>
instance JavaPrintableNamed AST.EnumeratedType where<br>
   javaLinesNamed parentName (AST.EnumeratedType memberDefinitions) =<br>
      [ &quot;public enum &quot; ++ asJavaId(parentName)<br>
      , &quot;{&quot;<br>
      ] ++ memberCodeLines ++<br>
      [ &quot;}&quot;<br>
      , &quot;&quot;<br>
      ]<br>
      where<br>
         memberCodeLines = indent $ javaLines memberDefinitions<br>
<br>
The indent function takes a list of strings and adds an indent to the<br>
beginning of every line.<br>
<br>
I can imagine this to be very inefficient as it builds many strings and<br>
concatenates them.<br>
<br>
In Ruby, I might do the same thing like this:<br>
<br>
class EnumeratedType &lt; JavaPrintableNamed<br>
   def writeTo(writer)<br>
      writer.print &quot;public enum &quot;<br>
      writer.puts self.asJavaId<br>
      writer.puts &quot;{&quot;<br>
      writer.indent do<br>
         self.memberDefinitions.writeTo(writer)<br>
         writer.puts<br>
      end<br>
<br>
where above, the writer.indent takes care of the indent, and everything is<br>
appended to a stream, which doesn&#39;t seem so bad in terms of efficiency.<br>
<br>
I&#39;m looking for a way to do something similar in Haskell.<br>
<br>
Anyone can give me a hand?<br>
<br>
Thanks<br>
<br>
-John<br>
<br>
<br>
_______________________________________________<br>
</blockquote>
<br>
You may want to investigate the standard module<br>
Text.PrettyPrint.HughesPJ, which contains a number of (I assume fairly<br>
efficient) combinators for pretty printing.<br>
</blockquote>
<br></div></div>
I second that. Also, there is uulib which has a pretty printing module that&#39;s quite similar:<br>
<br>
<a href="http://hackage.haskell.org/packages/archive/uulib/0.9.10/doc/html/UU-PPrint.html" target="_blank">http://hackage.haskell.org/packages/archive/uulib/0.9.10/doc/html/UU-PPrint.html</a><br>
<br>
I think both packages are based on the paper &quot;The Design of a Pretty-printing Library&quot; which can be found at <a href="http://www.cs.chalmers.se/%7Erjmh/Papers/pretty.ps" target="_blank">http://www.cs.chalmers.se/~rjmh/Papers/pretty.ps</a><br>

<br>
Not only do they provide abstractions for things like indentation, concatenation in different forms, etc., but they also are  more efficient than a naive implementation using lists.<br>
<br>
-chris<br><font color="#888888">
<br>
-chris<br>
</font></blockquote></div><br>