[erlang-questions] Maps in typespecs (and dialyzer)

Björn-Egil Dahlberg egil@REDACTED
Wed Jan 7 17:55:10 CET 2015


On 2015-01-05 23:43, José Valim wrote:
> Hello everyone,
>
> The typespecs 
> <http://www.erlang.org/doc/reference_manual/typespec.html> documentation 
> says dialyzer does not yet use map pairs information (which is fine). 
> The issue is that it does not describe what are the semantic 
> implications of map pairs in types. To be clear, the following type:
>
>     #{foo => any()}
>
>
> should:
>
> 1) match maps containing only the key foo
> 2) match maps containing at least the key foo

We've had some debate on this. Especially regarding mandatory and/or 
optional fields.

 From my viewpoint your second point is the correct one. You must 
specify the fields and types that are needed for your function to succeed.

I don't think it should be an error to over specify the fields (more 
keys than needed). Perhaps you want to construct a -type with a map with 
several fields but different fields are used in different functions 
where you specify that you are using this type.

> Additionally, what would #{_ => _} mean in any of the schemas above?

This is essentially what we are saying today .. though i would refrain 
from specifying it with underscore, #{ any() => any() } is a bit clearer.
Our contract says we accept a map containing any keys with any values, 
which is not very useful but valid. The jury is still out on empty map 
though.


// Björn-Egil

>
> *José Valim*
> www.plataformatec.com.br <http://www.plataformatec.com.br/>
> Skype: jv.ptec
> Founder and Lead Developer
>
>
> _______________________________________________
> 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/20150107/27e25ca6/attachment.htm>


More information about the erlang-questions mailing list