<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">23 янв. 2017 г., в 13:30, Dániel Szoboszlay <<a href="mailto:dszoboszlay@gmail.com" class="">dszoboszlay@gmail.com</a>> написал(а):</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">A function's type specification can be overloaded:<div class=""><br class=""></div><div class=""><font face="monospace" class="">-spec foo(integer()) -> integer()</font></div><div class=""><font face="monospace" class="">       ; (atom()) -> atom().</font></div><div class=""><br class=""></div><div class="">Is there a way I can use this overloaded function's type in non-spec contexts? Like I want to say <font face="monospace" class="">bar/1</font> takes a function as an argument that has a spec like <font face="monospace" class="">foo/1</font> above.</div><div class=""><br class=""></div><div class="">I can think of the following options, but neither of them is exactly what I want:</div><div class=""><br class=""></div><div class=""><font face="monospace" class="">-spec bar(fun((integer() | atom()) -> integer() | atom())) -> ok.</font></div><div class=""><font face="monospace" class="">%% Allows a function taking an integer and returning an atom.</font></div><div class=""><font face="monospace" class=""><br class=""></font></div><div class=""><font face="monospace" class="">-spec bar(fun((integer()) -> integer()) | fun((atom()) -> atom())) -> ok.</font></div><div class=""><font face="monospace" class="">%% Allows fun erlang:atom_to_list/1, which doesn't work on integers at all.</font></div></div></div></blockquote></div>Unfortunately, that requires having contravariant first-class types, which Dialyzer doesn’t support by design currently.<div class="">Best thing you can do in your case is writing fun((X) -> X) when X :: atom().</div></body></html>