[erlang-questions] dict() type issue

Michael Truog mjtruog@REDACTED
Fri Jan 3 18:04:10 CET 2014


Never mind about this.  I can understand why an is_dict/1 guard will never happen (dict is not a real type).  The only good solution (to this type checking need in a generic API, with dict) in Erlang is to wrap all your data structure usage in a tagged tuple like {dict, dict()} despite that being odd and annoying.  With the is_map/1 guard, maps can be checked as a real type, so it will be easier to use in a generic interface.

On 01/02/2014 02:56 PM, Michael Truog wrote:
> Hi!
>
> The dict() type being defined as opaque prevents it from being checked with other dictionary implementations that rely on tuples.  If you do "is_tuple(D), element(1, D) =:= dict" dialyzer will complain once it realizes that D is a dict(), despite the fact it is a tuple underneath the opaque type.  To help with the migration to maps, a new function is_dict/1 could help check the type during runtime, in a way that doesn't anger dialyzer.  Ideally, is_dict/1 would be a guard function, but I assume that is problematic unless it was added to the erlang module.  Is there any reason we wouldn't want an is_dict/1 function?
>
> Thanks,
> Michael




More information about the erlang-questions mailing list