I'm trying to specify a function in a header file. Like so:
-spec update(pid(), tuple(tuple(), integer(), atom()), tuple(atom(), atom())) -> tuple(tuple(), integer(), atom()).
Now I want to add some extra specification for this function because it has multiple 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}.
So I want to add these extra specifications, for the different parameters in this function, in my header file. I don't know how to do this, could someone help me with this?
I tried to do this but it gives 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.
In Erlang there are 2 types of numeric literals which are integers and floats.
spec adds up information about the code. It indicates the arity of the function and combined with -type declarations, are helpful for documentation and bug detection tools. Tools like Edoc use these type specifications for building documentation. Tools like Dialyzer use it for static analysis of the code.
7 Types and Function Specifications.
I found the answer here. I had to use the semi-colon ;
. I changed 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()).
into this:
-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()).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With