[Haskell-cafe] Re: Strings - why [Char] is not nice

John Goerzen jgoerzen at complete.org
Tue Sep 28 11:21:17 EDT 2004


[ haskell newbie alert ]

On 2004-09-20, Henning Thielemann <iakd0 at clusterf.urz.uni-halle.de> wrote:
>
> On Mon, 20 Sep 2004, Einar Karttunen wrote:
>
>> Size
>> 
>> Handling large amounts of text as haskell strings is currently not
>> possible as the representation (list of chars) is very inefficient. 
>
> Efficiency is always a reason to mess everything. But the inefficiency

Well put.

> applies to lists of every data type, so why optimizing only Strings, why
> not optimizing Lists in general, or better all similar data structures, as

Python has an interesting approach.  Strings are not implemented as
lists of characters, but they are an object of a generic type (I forget
what it's called; iterable maybe) that can be accessed like a list.
(Lists, of course, are also objects of that type.)

I assume typeclasses could lead to the same situation in OCaml.  It's
not a list, but it looks and acts like a list...

But anyway, having strings as lists of chars leads to some things that
are convenient:

 * (++) is both a list and a string concatenation operator

 * Pattern matching works well with strings (that's my #1 gripe about
   strings in OCaml)

 * Thanks to the laziness of Haskell lists, things such as "lines" are
   possible -- eliminating the hassle of loops/recursion to read file
   data or the ugliness of reading an entire file at once.

These are significant advantages to me.



More information about the Haskell-Cafe mailing list