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

Richard O'Keefe raoknz@REDACTED
Mon Apr 29 12:31:49 CEST 2019


It's not clear to me why you would have a record with
50 fields.  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.

Unless/until that's implemented, do it manually.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20190429/71664114/attachment.htm>


More information about the erlang-questions mailing list