[Haskell-cafe] How to pretty print code efficiently
newhoggy at gmail.com
Fri Jul 3 21:45:47 EDT 2009
Currently I'm pretty printing code by building arrays of strings and calling
indent. For example:
instance JavaPrintableNamed AST.EnumeratedType where
javaLinesNamed parentName (AST.EnumeratedType memberDefinitions) =
[ "public enum " ++ asJavaId(parentName)
] ++ memberCodeLines ++
memberCodeLines = indent $ javaLines memberDefinitions
The indent function takes a list of strings and adds an indent to the
beginning of every line.
I can imagine this to be very inefficient as it builds many strings and
In Ruby, I might do the same thing like this:
class EnumeratedType < JavaPrintableNamed
writer.print "public enum "
where above, the writer.indent takes care of the indent, and everything is
appended to a stream, which doesn't seem so bad in terms of efficiency.
I'm looking for a way to do something similar in Haskell.
Anyone can give me a hand?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe