title: Most efficient method of constructing and printing very large strings
body: <p>I have a program which constructs very large strings. Currently I am using lazy <code>ByteString</code>s. Here are the problem parameters summarized:</p>
  
  <p>The current implementation works up to about 500k characters, simply running out of memory afterwards (~600MB). I would like this (amount of characters) to run in under 50MB. </p>
  
  <p>The string isn't accessed while being built. This probably leads to a lot of thunks and hence the memory issue. I am using <code>Builder</code> to make the <code>ByteString</code>s, but it seems that there is no strict version of <code>Builder</code> (or at least I can't find it).</p>
  
  <p>The string cannot be put in the file while being built. The entire build operation has to happen before the string is placed in a file.</p>
  
  <p>I don't need unicode support. Even 7 bit ascii would do. I believe that <code>ByteString</code> doesn't waste memory to encode unicode characters though.</p>
  
  <p>Things I have tried:</p>
  
  <p>Calling <code>seq</code> on the <code>ByteString</code>s as they are being built. This seems to work for 50-100k characters but after that the effect is the same.</p>
  
  <p>Using strict <code>ByteString</code>s. I couldn't figure out how to use <code>Builder</code> with them, so I ended up using lists and <code>concat</code>.</p>
  
  <p>Using <code>UArray Int Char</code>. This means either knowing the size of the string in advance and allocating the entire array, or having a ton of intermediate data structures. </p>