[erlang-questions] Dialyzer type specifications for macros with bitstrings makes erlc barf

zxq9 <>
Sat Mar 19 03:05:24 CET 2016


Hi, Sachin.

On 2016年3月18日 金曜日 11:22:43 you wrote:
> Thanks a lot Craig
> Amazing , detailed information . However I do feel there is an
> inconsistency in the behavior of erlang compiler vs dialyzer.
> Inconsistencies
> =============
> 1. Although a type-spec doesn't allow you to specify a  "set" of objects,
> it lets us specify a set of integers e.g 0..12  etc.

But this isn't really a set definition, it is only specifying a *range*.

  -type zero_through_five() :: 0..5.

The above declaration is effectively shorthand for:

  -type zero_through_five() :: 0 | 1 | 2 | 3 | 4 | 5.

And that, when viewed as a union, is not so different from:

  -type odd_union() :: zero_through_five() | blah | tuple().

As for declaring an actual set... I suppose you can do this:

  -type odd_set() :: set:set(odd_union()).

But I *think* this is declaring that the set or any subset of odd_union()
members, not a fixed set that is all members of odd_union(). In any case,
it will be an actual set (no duplicates) where the union types themselves
are just union types and have nothing to say about how many of each member
type is involved. Neither, for that matter, do list declarations:

  -type odd_list() :: [odd_union()].

I don't think I've actually had any call for a set declaration like this.
But I'm sure there is some case out there where it would be useful.

Anyway, Erlang's type system and Dialyzer are permissive in nature, only
telling you when something is definitely wrong, instead of a stricter Haskell
sort of type system where anything that isn't clearly correct defaults to
being wrong. Just part of the tradeoff of this particular environment.

> 2. You can specify definitions as bitstring() or string()  instead of a set
> of values, but dialyzer complains that the return type
>      is a super-type of the set of values being returned .

By "set of values" do you mean "union of types"?

I'm not quite sure I'm following you, as I don't think I've ever seen this
warning or error. Can you show me an example? Some warnings/errors are a
bit cryptic, so I want to know what this one is before I run into it in my
own code. (Its only a matter of time...)


More information about the erlang-questions mailing list