Combining wl-pprint and ByteString?

Hi all, I want to do the following tasks in this order: 1. Read text from standard input (should this be stored internally in my program as a ByteString or as a String?) 2. Process the text via left justifying it and making it word-wrap (again, internally, should I store this as a ByteString or String?) 3. Format the text using the Wadler-Leijen Pretty Printer (to the best of my knowledge this only processes Strings, but not ByteStrings) 4. Print to Standard output the formatted (i.e. colourised, and justified) text (again, should this be as a ByteString or as a String?) I thought that the reason that most people use ByteString was for _performance_, but wl-pprint can only process Strings to the best of my knowledge. I would, ideally, like to use ByteStrings everywhere...all throughout my code. Is this possible with coloured text? I want to boost up the performance of my application dramatically, so in theory I could process everything as a String, then as the last second pack everything processed into a ByteString and print it out...I think that this might work. Then again it might not because of the types expected. Any help with this would be appreciated. Cheers, Mark Spezzano

On 9 November 2010 17:53, Mark Spezzano
Hi all,
I want to do the following tasks in this order:
1. Read text from standard input (should this be stored internally in my program as a ByteString or as a String?)
2. Process the text via left justifying it and making it word-wrap (again, internally, should I store this as a ByteString or String?)
3. Format the text using the Wadler-Leijen Pretty Printer (to the best of my knowledge this only processes Strings, but not ByteStrings)
4. Print to Standard output the formatted (i.e. colourised, and justified) text (again, should this be as a ByteString or as a String?)
I thought that the reason that most people use ByteString was for _performance_, but wl-pprint can only process Strings to the best of my knowledge.
I would, ideally, like to use ByteStrings everywhere...all throughout my code. Is this possible with coloured text?
I want to boost up the performance of my application dramatically, so in theory I could process everything as a String, then as the last second pack everything processed into a ByteString and print it out...I think that this might work. Then again it might not because of the types expected. Any help with this would be appreciated.
Well, I'm currently working on a Text version of wl-pprint, which will probably suit your needs better than Bytestring. As for coloured text, there's ansi-wl-pprint, but it's more for terminals (how exactly do you want to output your results?). -- Ivan Lazar Miljenovic Ivan.Miljenovic@gmail.com IvanMiljenovic.wordpress.com

Hi Ivan, Yes, I want it printed in a terminal window. I want to be able to run it from the command line in a terminal window, and have the text come up in colours (but very fast). My current version is already very fast, but I've heard everyone raving about how slow Strings were to use for I/O, so I wanted to _experiment_ with ByteStrings to see the performance difference. I'm experimenting with writing a Zork-like text adventure game and I just wanted to do some space/time profiling on different pieces of code and observe the results. I thought that ByteStrings might be the way to go, but can they be combined with the Doc type from the ansi-wl-pprint library? Mark On 09/11/2010, at 5:37 PM, Ivan Lazar Miljenovic wrote:
On 9 November 2010 17:53, Mark Spezzano
wrote: Hi all,
I want to do the following tasks in this order:
1. Read text from standard input (should this be stored internally in my program as a ByteString or as a String?)
2. Process the text via left justifying it and making it word-wrap (again, internally, should I store this as a ByteString or String?)
3. Format the text using the Wadler-Leijen Pretty Printer (to the best of my knowledge this only processes Strings, but not ByteStrings)
4. Print to Standard output the formatted (i.e. colourised, and justified) text (again, should this be as a ByteString or as a String?)
I thought that the reason that most people use ByteString was for _performance_, but wl-pprint can only process Strings to the best of my knowledge.
I would, ideally, like to use ByteStrings everywhere...all throughout my code. Is this possible with coloured text?
I want to boost up the performance of my application dramatically, so in theory I could process everything as a String, then as the last second pack everything processed into a ByteString and print it out...I think that this might work. Then again it might not because of the types expected. Any help with this would be appreciated.
Well, I'm currently working on a Text version of wl-pprint, which will probably suit your needs better than Bytestring.
As for coloured text, there's ansi-wl-pprint, but it's more for terminals (how exactly do you want to output your results?).
-- Ivan Lazar Miljenovic Ivan.Miljenovic@gmail.com IvanMiljenovic.wordpress.com _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On 9 November 2010 19:01, Mark Spezzano
Hi Ivan,
Yes, I want it printed in a terminal window.
I want to be able to run it from the command line in a terminal window, and have the text come up in colours (but very fast). My current version is already very fast, but I've heard everyone raving about how slow Strings were to use for I/O, so I wanted to _experiment_ with ByteStrings to see the performance difference.
I _think_ Bytestrings are more efficient when dealing with files, networks, etc.; I don't think there would be any noticeable improvement in efficiencies for terminal I/O (probably less, since I think - but am quite possibly wrong - that printing to stdout and reading from stdin still goes via String).
I'm experimenting with writing a Zork-like text adventure game and I just wanted to do some space/time profiling on different pieces of code and observe the results. I thought that ByteStrings might be the way to go, but can they be combined with the Doc type from the ansi-wl-pprint library?
Have you actually profiled your code to see if the I/O is indeed a bottleneck? And no, unless you fork and convert it, ansi-wl-pprint can't use Bytestrings. -- Ivan Lazar Miljenovic Ivan.Miljenovic@gmail.com IvanMiljenovic.wordpress.com

On 9 November 2010 08:01, Mark Spezzano
I want to be able to run it from the command line in a terminal window, and have the text come up in colours (but very fast). My current version is already very fast, but I've heard everyone raving about how slow Strings were to use for I/O, so I wanted to _experiment_ with ByteStrings to see the performance difference.
I very much doubt that you will see a difference in performance between String and Text for the amounts of data that you can fit on a terminal window. Cheers, Max
participants (3)
-
Ivan Lazar Miljenovic
-
Mark Spezzano
-
Max Bolingbroke