records

Robert Virding rv@REDACTED
Tue Dec 4 12:46:52 CET 2001


Hakan Stenholm <etxhste@REDACTED> writes:
>The imidiat problem can be solved by adding a guard 
>"foo(A, ...) when record(A, ...) ->" to do the type checking.
>
>This entier problem is realy due to the fact that records are not treated as a 
>unique data type inside the VM (virtual machine) - they are implemented as
>tuples. This makes it impossible to distinguish between a record and a tuple 
>that happens to look like a record, this is also a problem if you have a
>function like this:
>...
>It should be noted that all record accesses and updates end up as calls to 
>element/2 and setelement/3 i.e. tuple manipulating operations, this is done by
>the preprocessor during compilation.
>Record fieldnames are converted to indexes by the preprocessor as well.
>
>So when the code is actualy run, the VM has no idea that some tuples should
>be typechecked as records rather than simple tuples, i.e. records are only 
>"syntactic suger" and not realy a language entity.

This is, of course, all true, BUT in the documentation records are
defined to be tuples so it really shouldn't come as a surprise.  The
reason for this is that when records were first implemented it wasn't
possible at that time to easily add a new datatype in the
implementation.  This has changed today.

Seriously, how many people/apps would be severely burned if records
*were* made their own datatype?  It is possible to do but you have to
determine which solution hurts the most.

Robert



More information about the erlang-questions mailing list