[Haskell-cafe] Efficient string construction

Kevin Jardine kevinjardine at yahoo.com
Thu Jun 3 10:03:11 EDT 2010

(I've done a basic Google search on this with no results. Apologies if this has been asked before.)

I am coding a web application in which the content is a Unicode string built up over multiple functions and maintained in a State structure.

I gather that the String module is inefficient and that Data.Text would be a better choice.

Is it more efficient to build up a list of Text objects over time and combine them together with a single Data.Text.concat for the final output or to run Data.Text.append for each new string so that I am maintaining a single Text object rather than a list?

As Data.Text.append requires copying both strings each time, my gut feeling is that concat would be much more efficient, but Haskell has surprised me before, so I wanted to check.



More information about the Haskell-Cafe mailing list