[erlang-questions] Maps branch and disclaimers

Chris King colanderman@REDACTED
Wed Oct 30 16:13:51 CET 2013

On Wed, 30 Oct 2013 10:57:43 -0400, Björn-Egil Dahlberg <egil@REDACTED>  

> However, I think we can view maps as functions and the pairs as function  
> clauses. It should be the same problem >space, i.e. range and domains,  
> product and unions.
> so,
> -spec wat() -> #{ binary() => integer()}.
> would exhibit the same problem/solution as,
> -spec foo(binary()) -> integer().
> foo(B) when is_binary(B) -> binary_to_integer(B).

That works for heterogeneous maps (i.e. supporting selection).  But for  
the example you give (a homogeneous map, supporting enumeration) this  
fails, as that signature requires that the function be defined for *all*  
binaries.  Clearly this is impossible!

-spec foo(Key1) -> Value1Type.
-spec foo(Key2) -> Value2Type.

works for heterogeneous maps, but not homogeneous maps.  For a homogeneous  
map, the signature you need is:

-spec foo(KeyType) -> {ok, ValueType} | none.

because "Key" here is necessarily a full type rather than a single value  
or two, and the map, being finite, cannot contain a value for every  
possible key.

> I've looked at your other mail but I don't have time to get into the  
> details right now.Thank you for feedback! It is much appreciated and I  
> will look into it when the time arrives!

Thanks for listening.  I come from the OCaml world which *almost* has  
heterogeneous maps done right (its object types); AFAIK no other language  
does (beside SQL), hence why I am so engaged :)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20131030/a2708461/attachment.htm>

More information about the erlang-questions mailing list