Making Erlang records more reliable

Roger Price rprice@REDACTED
Thu Sep 22 18:43:38 CEST 2005

This seems to me to be a most interesting proposal.  I implemented
something similar in a pi-calculus language for which I developed an
Erlang emulator.    There were some syntactic differences about which we
need not waste time, but there were also some typing differences.

1. The pi-calculus language is strictly typed, but is comfortably
translated to dynamically typed Erlang.   I believe that simplicity and
dynamic typing are part of the strengths of Erlang and I do not wish to
change this.

2. I distinguished [1] between the type function, represented by the tag,
which maps the record type to the defined type, and name of the defined
type.  SGML and XML do not make this separation, confusing the two ideas.
In an Erlang-like notation, this could be expressed as


where Tag is the name of a type function

     Tag : TupleType -> DefinedType

I understand that this is the intent of the proposed new declaration
which taken with the existing declaration -record(TagName,Tuple)
provide the type function TagName : Tuple -> RecordName

3. I found that converging the ideas of elements and records, and
replacing the SGML/XML world's validation-by-parsing by type checking
provides additional safety assurances than cannot be achieved by SGML/XML

4. Rather than make a lot of experimental changes to the Erlang language,
I would personally prefer to see such ideas included in a strictly typed
subset of Erlang which could be (automatically) type checked before
re-issue as "true" Erlang.  Maybe in the long term the ideas will also
appear in the Erlang language, but an experimental front end would be
helpful in the short term.  I started work on such a front end, but I have
so far made little progress.
On Thu, 22 Sep 2005, Richard A. O'Keefe wrote:

> What this doesn't help with, of course, is people taking records apart
> or building them with hand-written code.

If I understand the proposal correctly the combined effect of -record_tag
and -record is similar to ML's datatype declaration:

datatype DefinedType = Tag of TupleType

ML datatypes are conveniently deconstructed using hand-written pattern
matching, which seems to me to be a natural way of deconstructing <Tag
{([Label=]Field)*}> elements.   Such deconstructions will be difficult
to avoid.
On Thu, 22 Sep 2005, Joe Armstrong wrote:

Here is a proposal for a template language (suitable for yaws)
       @module misc
       @template main(E)
       <? M= 30, N = 20, "" ?>
       <table><tr><td bgcolor="grey"> <? X ?> </tr></td></table>
       fac(0) -> 0;
       fac(N) -> N * fac(N-1).

If the "<Tag Tuple>" syntax of records were sufficiently developed, it
would be possible not only to write such a template in Erlang, but to
perform a thorough type check validation of the elements and their
attributes against the code; something which is difficult in independent
template languages.


[1] Pint User's Guide,, "Element type
declaration", page 37.

More information about the erlang-questions mailing list