<div dir="ltr">I would not phrase it like that... you are hopefully not writing specifications just for the sake of testing or being shouted at by Dialyzer! :-) <span style="line-height:1.5">If your function should work for the empty list, then your specification should include it.</span><div><span style="line-height:1.5"><br></span></div><div><span style="line-height:1.5">It is true, however, that with an "[atom(),...]" spec (non-empty list of atoms), you will get an error, as this type has no values in common with the "[integer()]" (possibly empty list of integers).</span></div><div><span style="line-height:1.5"><br></span></div><div><span style="line-height:1.5">Stavros</span></div></div><br><div class="gmail_quote"><div dir="ltr">On Tue, Apr 19, 2016 at 10:32 AM PhayTsukiming <<a href="mailto:moonsolo@gmail.com">moonsolo@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Thanks for you explanation. One more question: should I use non empty list specification to make dialyzer complain? </div><div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Tue, Apr 19, 2016 at 4:03 PM Stavros Aronis <<a href="mailto:aronisstav@gmail.com" target="_blank">aronisstav@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p dir="ltr">Hi!</p>
<p dir="ltr">The most general type that foo can have is [number()] -> [number()]. The spec restricts both number() instances to just integer(). Then, since bar's only argument is given as is to foo, it should also be [integer()].</p>
<p dir="ltr">If you specify bar's argument as atom() then there is no way to make a successful call to foo and Dialyzer complains. If however bar's argument is a list of atoms, then there is a way, though a bit trivial, for a call to succeed: an empty list is both a valid list of atoms and a valid list of integers.</p>
<p dir="ltr">Dialyzer can see this, and does not complain. Perhaps a patch is needed, for a warning of type "only the empty list satisfies the given spec"...</p>
<p dir="ltr">Cheers,</p>
<p dir="ltr">Stavros</p>
<br><div class="gmail_quote"></div><div class="gmail_quote"><div dir="ltr">On Tue, 19 Apr 2016, 08:50 PhayTsukiming, <<a href="mailto:moonsolo@gmail.com" target="_blank">moonsolo@gmail.com</a>> wrote:<br></div></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi list, <span style="line-height:1.5">I am new to erlang and dialyzer. I have encounter a problem when I tried to fiddle with type specifications. </span><div><span style="line-height:1.5"><br></span></div><div><span style="line-height:1.5">Say, I have two functions:</span></div><div><span style="line-height:1.5"><br></span></div><div><div>-module(t).</div><div>-export([foo/1, bar/1]).</div><div><br></div><div>-spec foo([integer()])->[integer()].</div><div>foo(Arg)-></div><div>    [I+1||I<-Arg].</div><div><br></div><div>-spec bar(atom())->[integer()].</div><div>bar(_Arg)-></div><div>    foo(_Arg).</div><div style="line-height:1.5"><br></div></div><div style="line-height:1.5">Then apply dialyzer to this module and dialyzer warns:</div><div style="line-height:1.5"><br></div><div>t.erl:8: Invalid type specification for function t:bar/1. The success typing is ([integer()]) -> [integer()]<br></div><div><br></div><div>But if I change the specification of bar to:</div><div><br></div><div><div>-spec bar([atom()])->[integer()].</div></div><div><br></div><div>dialyzer will show no warnings. My intention is to make sure the argument of bar is the same type of list as the argument of foo. </div><div><br></div><div>Is this normal? Do I miss or misunderstand something about success typing or dialyzer?</div><div><br></div></div></blockquote></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
</blockquote></div>
</blockquote></div></div></blockquote></div>