Programming components

David Hopwood david.nospam.hopwood@REDACTED
Thu Aug 25 18:13:27 CEST 2005


Joe Armstrong (AL/EAB) wrote:
> Erlang has no strings - ie there is NOT a string data type.
> 
> "abc" is NOT a string but shorthand for [97,98,99]
> 
> Now suppose I see [97, 98, 99] on some I/O channel
> what does this mean? is it to be interpreted as a list of three integers
> or as a string? - nobody knows.
> 
> Most Erlang programmers choose to represent strings as "lists of integers" and
> write "abc" in their programs when they wish to create a string.
> 
> I am suggesting they should use <<"abc">> (a binary)
> 
> This all has to do with making a simple type system that mays Erlang terms onto
> XML data structures in an isomorphic manner.

How does using binaries solve this problem? A binary is an octet sequence;
"strings" are character sequences (usually represented as code unit sequences).

A binary can be used to *represent* a string in a charset with 8-bit code
units, but you also need some way to distinguish such a thing from "raw"
octet sequences, and possibly to distinguish representations using different
charsets if more than one charset is supported.

(I'm using the W3C character encoding model here, which is the model that
XML uses. See <http://www.w3.org/TR/charmod/>.)

-- 
David Hopwood <david.nospam.hopwood@REDACTED>




More information about the erlang-questions mailing list