[erlang-questions] Strings as Lists
Richard A. O'Keefe
Thu Feb 14 02:28:38 CET 2008
On 13 Feb 2008, at 7:21 am, Christian S wrote:
> That is the reason. Hysterical Raisins.
> There was a time when Erlang didn't have binaries.
There was a time when Erlang didn't have _anything_,
but that's almost surely not the reason.
> Someone thought it
> would be a good idea to make "ABC" a way to write [65,66,67].
Don't forget, Erlang was heavily influenced by Prolog and Strand84.
If memory serves me correctly, the original prototype implementation
was done in Prolog, and the Prolog reader has read "ABC" as [65,66,67]
since the late 1970s at least.
It's not Hysterical Raisins at all: it is simplicity (the preferred
sequence type in Erlang is lists, and strings are just sequences of
characters), power (because any time someone defines a function on
lists you get to use it on strings, and there are *lots* of useful
list functions), and processing efficiency (because working down
one character at a time doesn't require allocating *any* new storage,
not even for slices).
ByteStrings were added to Haskell (actually in two flavours) to support
high volume I/O. One of the reasons they've seen a lot of acceptance is
that various people have gone to a lot of trouble to make them LOOK as
much like lists as possible. Thanks to Haskell's typeclass machinery,
that can be "very much indeed" (see the ListLike package, the use of
means that you can continue to write code that works on lists *or*
The one thing that bytestrings aren't much good for these days, of
is holding *decoded* characters.
It's important to realise that in ANY programming language there is
one way to represent strings. For example, even for character=byte
three different representations supported in C89, and C89 programs
to deal with a fourth. You don't *have* to stick with the one that the
compiler translates "ABC" to.
More information about the erlang-questions