Multiple specifications for the same function in the Erlang header file

I am trying to specify a function in a header file. For instance:

-spec update(pid(), tuple(tuple(), integer(), atom()), tuple(atom(), atom())) -> tuple(tuple(), integer(), atom()). 

Now I want to add an additional specification for this function, because it has several different parameters.

 update(_Pid, {Specs, infinity, _State}, {Step}) -> timer:sleep(10000), {{Specs, infinity}, {Step}}; update(_Pid, {Specs, infinity, _State}, {ExtraInfo, Step}) -> timer:sleep(10000), {{Specs, infinity}, {ExtraInfo, Step}}; update(_Pid, {Specs, N, _State}, _Info) when N < 2 -> {Specs, N, stop}; update(_Pid, {Specs, N, _State}, {notTaken, Step}) -> {Specs, N, Step}; update(_Pid, {Specs, N, _State}, {taken, Step}) -> {Specs, N - 1, Step}. 

Therefore, I want to add these additional specifications for the various parameters of this function to my header file. I do not know how to do this, can someone help me with this?

I tried to do this, but he gave me compilation errors:

 -spec update(pid(), tuple(tuple(), integer(), atom()), tuple(atom(), atom())) -> tuple(tuple(), integer(), atom()). -spec update(pid(), tuple(tuple(), atom(), atom()), tuple(integer(), atom())) -> tuple(tuple(), atom(), atom()). -spec update(pid(), tuple(tuple(), atom(), atom()), tuple(atom())) -> tuple(tuple(), atom(), atom()). 

Thanks in advance.

+6
source share
1 answer

Found the answer here: http://erlang.org/doc/reference_manual/typespec.html

I had to use ';'

change this:

 -spec update(pid(), tuple(tuple(), integer(), atom()), tuple(atom(), atom())) -> tuple(tuple(), integer(), atom()). -spec update(pid(), tuple(tuple(), atom(), atom()), tuple(integer(), atom())) -> tuple(tuple(), atom(), atom()). -spec update(pid(), tuple(tuple(), atom(), atom()), tuple(atom())) -> tuple(tuple(), atom(), atom()). 

in it:

 -spec update(pid(), tuple(tuple(), integer(), atom()), tuple(atom(), atom())) -> tuple(tuple(), integer(), atom()); (pid(), tuple(tuple(), atom(), atom()), tuple(integer(), atom())) -> tuple(tuple(), atom(), atom()); (pid(), tuple(tuple(), atom(), atom()), tuple(atom())) -> tuple(tuple(), atom(), atom()). 
+2
source

Source: https://habr.com/ru/post/987911/


All Articles