I am new to dialyzer, and I am hoping someone could give me a quick idea of it's operation by answering this question.
I would think that the following function, given a number X and a non-negative integer N, would produce a number. (X to the Nth power.)
-spec pow(X :: number(), N :: non_neg_integer) -> number().
pow(X, N) ->
pow(X, N, 1).
pow(_X, 0, R) ->
R;
pow(X, N, R) ->
pow(X*X,
N bsr 1,
if
N band 1 =:= 0 ->
R;
true ->
X*R
end).
But dialyzer doesn't like my specification. It tells me:
Invalid type specification for function t:pow/2.
The success typing is (_,integer()) -> any()
What it suggests seems to me to be an overly inclusive specification. Can someone explain why it does this, and whether there is any way to get a more restrictive type specification accepted?