[erlang-questions] Static Map ( Keys known at compile time )

Kostis Sagonas kostis@REDACTED
Mon Apr 29 21:34:08 CEST 2019


On 4/29/19 12:31 PM, Richard O'Keefe wrote:
> It's not clear to me why you would have a record with
> 50 fields.

Same here, of course.

>  Imagine for a moment that Erlang's record
> declaration syntax were generalised slightly:
> 
> '-' 'record' '(' <name> ',' <group> ')' '.'
> where
>    <group> = '{' (<field> | <group>)+',' '}'
>    <field> = <name> ['=' <default expr>]
> 
> The generalisation here is allowing <group>s as well
> as <field>s inside <group>s.  A nested group would be
> a nested tuple with no element reserved for a tag.  So
> -record(foo, {{a,b},{c,d}}).
> means that a typical instance would look like
> {foo,{A,B},{C,D}}.
> The time to fetch a field would be proportional to the
> number of groups it is in; the time to replace it would
> be proportional to the sum of the sizes of the groups
> it is.
> Put nested fields into groups that are commonly read
> or written together, and you trade a small increase
> in read time for a large decrease in write time, with
> automatic economisation in pattern matching, but needing
> special attention from the compiler to fully economise
> updates.
> 
> That would be a nice extension of Erlang records, letting
> you make performance tradeoffs just by adding and removing
> curly braces with no change to code elsewhere.

I see very little benefit, if any at all, compared to the (natural, IMO) 
alternative of using nested records for such use cases:

  -record(foo, {#grp1{a,b},#grp2{c,d}}).

which requires no language (or implementation) extension.

What am I missing?

Kostis



More information about the erlang-questions mailing list