[erlang-questions] AST record syntax improvement

Daniel Dormont dan@REDACTED
Mon May 23 05:16:00 CEST 2011


On Sun, May 22, 2011 at 6:26 PM, Robert Virding <
robert.virding@REDACTED> wrote:

> I think the actual syntax is the least of your problems. The existing
> syntax looks like it does much because of the properties of erlang and of
> records. Records were added to give named fields to tuples and to be at
> least as fast as directly using the tuple operations. This means that
> everything had to be done at compile-time. And as erlang is dynamically
> typed without any typed declarations then all type information has to be
> given at each record operation.
>
> Recless tried to be smart and get around this and only require the field
> names and not the record names. There are really only two ways of doing this
> properly:
>
> 1. Require that all field names are unique in all records.
> 2. Require some typing "help" so the system can work out which record types
> are being accessed.
>
>
I'm not sure why I have Haskell so much on my mind these days, but anyway:
#1 is precisely what Haskell does. In addition, as shown in my example
below, field names live in the same namespace as variables. It is not my
favorite feature in that language.



> The first is very difficult to work with in any large project. It would
> even be difficult for all OTP records. The second would mean requiring
> static type declarations to work properly and in all situations, which would
> be a fundamental change to the current Erlang language. It would, in fact,
> be a new language.
>
> Another thing to be aware of is that pattern matching and '=' complicate
> the syntax. I personally don't think that
>
> NewProject = Project.owner.address.city = "Boston".
>
> is that much more intelligible.
>
>
Just for fun, in Haskell this currently looks like:

newProject = project { owner = (owner project) {  address = (address (owner
project)) { city = "Boston" }}}

Not pretty.

Then again, is it common to need to do nested updates of fields like that?

 dan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20110522/0073e695/attachment.htm>


More information about the erlang-questions mailing list