[erlang-questions] Strings as Lists

denis dloutrein.lists@REDACTED
Thu Feb 14 20:05:51 CET 2008

In the project I currently work on, we faced a problem with the string. Not
because there are stored as list (it's very handy sometimes), but because we
can't find the type of the data. It's really frustating to not being able to
know when we receive a list of integer, if it's really a list of integer or
a string. This is the case when you need to convert your data into another
representation, for instance json or whatever format. I know that there are
tricks like {string, [...]}, but you need to parse all your data before to
convert it.
My wish is to have a real string type, whatever its representation is (list,
binaries, ...)


> -----Message d'origine-----
> De : erlang-questions-bounces@REDACTED [mailto:erlang-questions-
> bounces@REDACTED] De la part de Richard Carlsson
> Envoyé : mardi 12 février 2008 12:01
> À : tsuraan
> Cc : Erlang Questions
> Objet : Re: [erlang-questions] Strings as Lists
> tsuraan wrote:
> > Why does erlang internally represent strings as lists?  In every
> > language I've used other than Java, a string is a sequence of octets,
> > just like Erlang's binary type.  I know that you can represent a string
> > efficiently by using <<"string">> rather than just "string", but why
> > doesn't erlang do this by default?  Is it just because pre-12B binary
> > handling wasn't as efficient as list handling, or is Erlang intended to
> > support UTF-32?
> Strings as lists is simple and flexible (i.e., if you already have lists,
> you don't need to add another data type). Functions that work on lists,
> such as append, reverse, etc., can be used directly on strings; you
> don't need to program in different styles if you're traversing a list
> or a string; etc. Other languages that represent strings as lists include
> Prolog (which was a big influence on Erlang) and Haskell. That said, in
> larger systems it is better to represent string constants in a more
> space-efficient way. Binaries let you do this in Erlang, but they were
> a later addition to the language, and the syntax for constructing and
> decomposing binaries came even later.
>      /Richard
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions

More information about the erlang-questions mailing list