[erlang-questions] Typed records and erl_parse

Tobias Lindahl Tobias.Lindahl@REDACTED
Wed Dec 6 09:44:23 CET 2006


Robert Virding wrote:
> The trouble is you don't know who will suffer. Not everyone is on the 
> mailing list. Or there might be some piece of old code which happily 
> chugs along doing what it is supposed to until one day it crashes 
> because someone pulls the rug out from under its feet.

Yes, this is what I am afraid of, and I am also aware of that not 
everyone using Erlang is on the list. My question is more meant as a 
survey amongst the largest collection of Erlang users I could get my 
hands on. If all started screaming in horror I would know that it wasn't 
a good idea :-)

> Why not leave the old one as it is and add a new record_declaration 
> attribute? And a function_declaration attribute as well while you are at 
> it as that seems to be the way the wind is blowing.

This was the original implementation but it had some problems:

1. We could have both record declarations and type declarations for the 
same record. However, this would be an obvious source to 
inconsistencies, for example if you add a field to the record you would 
have to do it twice.

2. If we allow for the old record declaration and also the new typed 
record declaration, all uses of the new record would break all tools 
anyway since they wouldn't recognize the new attribute.

3. One way of having the same record declaration in two flavors is to 
simply allow type declarations in the old record declaration, and this 
is what we have chosen.

Obviously, 2 and 3 have some problems in common, such as breaking tools. 
But, 3 looks nice and allows for incrementally adding type annotations 
to single fields in the old records with very little trouble.

As Björn suggested, the compiler could start generating the new 
representation, but also handle the old, at least for some time and 
possibly with some compiler option. The implementation we have in mind 
is simple to map/filter back to the old representation, so if something 
breaks in a bad way there is a simple solution to this.

As for type declarations in functions, we are looking into that as well, 
and the current version is to have declarations in edoc style. One might 
argue that we should do this also for records for consistency, but since 
records already have a declaration it seems better to make use of it. If 
functions had some kind of prototype declaration we would use that too.

Let me also say that we are not really trying to make Erlang a 
statically typed language, but since programs are typically written in a 
reasonably type-friendly way, e.g., records are typically typed beasts 
since they are used in a particular way, we are merely trying to expose 
this to the programmer, and also allow some guidance to tools such as 
Dialyzer by allowing the programmer to state her/his intentions.

Tobias




More information about the erlang-questions mailing list