[erlang-questions] specs for fixed length lists
Richard Carlsson
carlsson.richard@REDACTED
Sun Jul 8 21:58:58 CEST 2012
On 07/08/2012 07:47 PM, Tony Rogvall wrote:
> While thinking about this problem I wrote the following spec:
>
> -spec get_buttons() ->
> {ok,{boolean(),{boolean(),{boolean(),{boolean(),[]}}}}}.
>
> get_buttons() ->
> {ok,{true,{true,{false,12}}}}.
>
> This passed dialyzer!
>
> The reason (I suppose) is that the analysis is limited to depth = 2 (or 3).
> Running typer while commenting out the spec gives:
>
> -spec get_buttons() -> {'ok',{'true',{'true',{_,_}}}}.
>
> I guess this is the real reason why dialyzer can not handle fixed size
> lists (at least not a list with a length greater than 3)
Dialyzer is still pretty poor at handling recursive tuple structures, as
you noted, and uses depth-k limitation (I don't remember the details,
and they've probably changed since I last looked at that code). But
lists are treated differently from tuples. It is assumed that most sane
uses of lists will not depend on the order of elements from a type
perspective. This lets Dialyzer use a less exact approximation, which
still captures most of the useful information for most programs but
without slowing down the type analysis too much.
/Richard
More information about the erlang-questions
mailing list