Why are strings linked lists?
Ben Escoto
bescoto at stanford.edu
Thu Nov 27 19:32:45 EST 2003
Hi, can someone tell me why Haskell strings are linked lists? I have
had some problems with Haskell strings:
1. Today I spend a few hours trying to track down a memory leak. It
turns out I just didn't realize how much space a string takes up.
On my machine "replicate 5000000 'a'" will use 90MB of space!
2. They are extremely slow for most operations like writing to disk,
adding something to the end, concatenation, etc.
3. They make learning Haskell harder. Lazy IO functions like
hGetContents are kind of slick in a shallow way, but I was
confused about the Haskell IO model because I thought of this as
the normal way IO was done, not something you could only set up
through unsafeInterleaveIO or similar.
Python's strings are also immutable, but they work great and are
really convenient. They are apparently implemented as variable length
arrays.
--
Ben Escoto
More information about the Haskell
mailing list