[erlang-questions] Matching Empty maps

Dmytro Lytovchenko dmytro.lytovchenko@REDACTED
Tue Feb 7 12:48:13 CET 2017


Trying to have a comfortable syntax brings all sorts of special cases not
covered. One should use == or =:= in a guard, or true = (X == #{}) which is
ugly.

2017-02-07 12:45 GMT+01:00 Joe Armstrong <erlang@REDACTED>:

> Ten minutes ago I was happily recursing down a list and discovered
> to my horror that an empty map isn't an empty map.
>
> 1> #{} = #{a => 1}.
> #{a => 1}
>
> The documentation actually says:
>
> <quote>
> #{} = Expr
>
> This expression matches if the expression Expr is of type map,
> otherwise it fails with an exception badmatch.
> </quote>
>
> So #{} is an empty map in an argument position but not an empty map
> in a pattern.
>
> So this is not a bug since the system does what the documentation says
> but it is very weird.
>
> Is there some deep reason for this that I've missed ??????
>
> Very Puzzled
>
> /Joe
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20170207/ed2be384/attachment.htm>


More information about the erlang-questions mailing list