[Haskell-cafe] Efficient string construction

Daniel Fischer daniel.is.fischer at web.de
Fri Jun 4 04:27:22 EDT 2010

On Friday 04 June 2010 00:41:58, Bryan O'Sullivan wrote:
> On Thu, Jun 3, 2010 at 9:16 AM, Daniel Fischer 
<daniel.is.fischer at web.de>wrote:
> > String can be quite memory efficient. As a stupid example,
> >
> > length (replicate 10000000 'a')
> >
> > will need less memory than the equivalents using ByteString or Text.
> Actually, this will be fused with Data.Text, and should execute more
> quickly and in less space than String.

Right, forgot about fusion. However, that requires the code to be compiled 
with optimisations, I think (well, one should never compile ByteString or 
Text code without).

In which case

"length/replicate" forall n x. length (replicate n x) = max 0 n

would be at least as good as the Data.Text thing ;)

Or, to be more fair, if you use Data.List.Stream, it should be fused too 
and be equally efficient as Data.Text.

More information about the Haskell-Cafe mailing list