[Haskell-cafe] Efficient string construction

Edward Kmett ekmett at gmail.com
Thu Jun 3 13:10:30 EDT 2010


You might also look at Data.Rope from the rope library, which provides an
O(1) append for strict bytestring chunks, and the ability to decode UTF-8
chars from the result.

http://hackage.haskell.org/packages/archive/rope/0.6.1/doc/html/Data-Rope.html

I'd also be happy to work with you if the current API falls short of your
needs.

-Edward Kmett

On Thu, Jun 3, 2010 at 10:03 AM, Kevin Jardine <kevinjardine at yahoo.com>wrote:

> (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.
>
> Kevin
>
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20100603/e412dedd/attachment.html


More information about the Haskell-Cafe mailing list