Type Specification of net:getnameinfo()

Nalin Ranjan ranjanified@REDACTED
Tue Jan 26 13:12:08 CET 2021


Type <https://erlang.org/doc/man/net.html#getnameinfo-2> of
net:getnameinfo() is specified in the source file
<https://github.com/erlang/otp/blob/master/lib/kernel/src/net.erl#L203>,
and the one prevailing in the docs is as below:-

-spec getnameinfo(SockAddr, Flags) -> {ok, Info} | {error, Reason} when
SockAddr :: term(),
Flags :: name_info_flags() | undefined,
Info :: name_info(),
Reason :: term().

Currently, the type is SockAddr :: term(), and could have been SockAddr ::
socket:sockaddr().

I think fixing it in the source at L221
<https://github.com/erlang/otp/blob/master/lib/kernel/src/net.erl#L221>
should fix it in the documentation as well. But please let me know if it
doesn't.

However, I am myself confused about the way the type is specified, so
thought I will discuss first before opening a PR.

It is not the net:getnameinfo/1 that I am confused, but about the
net:getnameinfo/2. I don't understand the usage of *ifndef* and *else *while
specifying this type specification. If you could please point me to a place
where I can understand these 2 better. I don't want to make wild guesses
here while I am working through the foundations of Erlang.

It could have been simpler had this specification been written like below,
even though whatever "ifdef" is doing out there is to be taken into
consideration:-

SockAddr :: socket:sockaddr() | term(),
Flags :: name_info_flags() | undefined,
Info :: name_info(),
Reason :: term()

Please let me know if there is any misconstrusion on my part.

Thanks and Regards
Nalin Ranjan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20210126/cc82642a/attachment.htm>


More information about the erlang-questions mailing list