[erlang-questions] Maps branch and disclaimers

Anthony Ramine n.oxyde@REDACTED
Wed Oct 30 16:36:12 CET 2013


In the foo/1 spec, the binary() doesn’t mean that foo/1 handles *all* binaries, it means that if you give something that is not a binary(), the call is guaranteed to fail.

PS: Your MUA sends rich text in 12px.

-- 
Anthony Ramine

Le 30 oct. 2013 à 16:13, Chris King <colanderman@REDACTED> a écrit :

> On Wed, 30 Oct 2013 10:57:43 -0400, Björn-Egil Dahlberg <egil@REDACTED> wrote:
> 
> 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 :)
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions




More information about the erlang-questions mailing list