Standard Library for text formatting?
Hi, Is there a standard haskell library for formatting text? Ie something with similar (or better) functionality to C's sprintf? I've done a bit of a search and haven't come up with much. In particular, I am looking for a routine that allow me to left or right justify text within a fixed column width. Presumably I could write this myself, but it would be better to use a standard library if there is such a thing. Cheers, Mark. -- Dr Mark H Phillips Research Analyst (Mathematician) AUSTRICS - smarter scheduling solutions - www.austrics.com Level 2, 50 Pirie Street, Adelaide SA 5000, Australia Phone +61 8 8226 9850 Fax +61 8 8231 4821 Email mark@austrics.com.au
Hi again, After doing some searching, it seems that "pretty printing" is a prominant "Haskell way" of doing text output. I still am interested in finding a library of standard text formatting (String formatting) functions, but it seems like it might be worth my while investigating pretty printing. So far there seem to be three candidate pretty printing libraries: 1. A library by Simon Peyton Jones http://research.microsoft.com/~simonpj/downloads/pretty-printer/pretty.html 2. A library by the Software Technology Group http://www.cs.uu.nl/groups/ST/Software/PP/ 3. The following library http://www.cs.uu.nl/~daan/pprint.html (This one doesn't seem to be mentioned at haskell.org --- any reason why?) Could anyone comment on the pros and cons of each of these libraries, plus any other libraries I've missed that are worth of note? It would be helpful to know what libraries are worth investing my time finding out about. (And of course, I'd still love to hear about simple string formatting libraries.) Cheers, Mark. -- Dr Mark H Phillips Research Analyst (Mathematician) AUSTRICS - smarter scheduling solutions - www.austrics.com Level 2, 50 Pirie Street, Adelaide SA 5000, Australia Phone +61 8 8226 9850 Fax +61 8 8231 4821 Email mark@austrics.com.au
Dr Mark H Phillips wrote:
Hi again,
After doing some searching, it seems that "pretty printing" is a prominant "Haskell way" of doing text output. I still am interested in finding a library of standard text formatting (String formatting) functions, but it seems like it might be worth my while investigating pretty printing.
Pretty printing is not very suited for printf like formatting, left/right justifying text is easy though: -- left/right justify the string "xs" in a fieldwidth "n". leftJustify n xs = xs ++ replicate (n - length xs) ' ' rightJustify n xs = replicate (n - length xs) ' ' ++ xs Jan
participants (2)
-
Dr Mark H Phillips -
Jan Kort