njl*_*son 1 erlang type-systems dialyzer
我是透析器的新手,我希望通过回答这个问题,有人可以快速了解它的操作.
我认为,给定数字X和非负整数N的下列函数将产生一个数字.(X到N次幂.)
-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).
Run Code Online (Sandbox Code Playgroud)
但透析器不喜欢我的规格.它告诉我:
Invalid type specification for function t:pow/2.
The success typing is (_,integer()) -> any()
Run Code Online (Sandbox Code Playgroud)
它在我看来是一个过于包容的规范.有人可以解释为什么会这样做,以及是否有任何方法可以接受更严格的类型规范?
| 归档时间: |
|
| 查看次数: |
800 次 |
| 最近记录: |