[erlang-questions] Maps

Loïc Hoguin essen@REDACTED
Tue May 14 13:38:11 CEST 2013

On 05/13/2013 08:27 PM, Björn-Egil Dahlberg wrote:
> - Deep updates of Maps are not covered by this EEP. We would welcome
> suggestions on this.

I think what Kenneth had in his talk was good. But

Simple update:
   M#{ K => V }

Nested update:
   M#{ K }#{ DK => DV }

I personally would prefer a more powerful:
   M#{ K #{ DK => DV }}

Because it allows you to write things like:
   M#{ K #{ DK => DV }, K2 => V2 }

And update multiple levels at once.

I know K can be a map, but deep update only works on values, the same 
way normal update only works on values, so no confusion is possible, 
we're only updating values, not K itself. If you feel an operator is 
needed it can be introduced between K and # in the two examples above.

Programmatically this would translate as extracting the map found at key 
K, and ensuring it's a map, updating this map with DK => DV, then 
placing this map back into the key K in map M along with setting V2 in 
key K2.

It doesn't sound hard to implement in the compiler, it's just unrolling 
things for access and rolling back again for the actual update. Exactly 
what we do manually today.

It should also be easy to compile to an optimized deep update with this 
syntax as you got everything in a single expression.

Note: If you are not interested in it despite how simple it is please at 
least ensure it can be done with a parse transform.


Loïc Hoguin
Erlang Cowboy
Nine Nines

More information about the erlang-questions mailing list