[Haskell-cafe] The question of ByteString

Tim Chevalier catamorphism at gmail.com
Fri Nov 2 16:01:30 EDT 2007


On 11/2/07, Andrew Coppin <andrewcoppin at btinternet.com> wrote:
> Somewhat related to the discussions about Haskell's performance...
>
> String. ByteString. Do we really need both? Can one replace the other?

You can't get rid of "String" because a String is just a [Char].
Requiring the element type of a list to be "anything except Char"
would be silly. In addition, it's useful to have a String that you can
apply arbitrary list operations to when performance isn't a concern
(i.e., most of the time). Finally, removing String would break
existing code.

> Why is one faster? Can't we make *all* lists this fast? [insert further
> variations here]

ByteString takes advantage of the fact that the elements are, well,
bytes. The operations are optimized for reading large amounts of text,
but not necessarily for other applications. Lists are a parameterized
type, so the elements of a list are pointers to arbitrary data. So
that's why the same tricks as ByteString don't apply to general lists.
That isn't to say that there aren't possible optimizations which
haven't yet been dreamed of.

Cheers,
Tim

-- 
Tim Chevalier * catamorphism.org * Often in error, never in doubt
"It is a defect of God's humour that he directs our hearts everywhere
but to those who have a right to them." -- Tom Stoppard


More information about the Haskell-Cafe mailing list