[erlang-questions] Overloaded function specifications as types
Dániel Szoboszlay
dszoboszlay@REDACTED
Mon Jan 23 11:30:54 CET 2017
A function's type specification can be overloaded:
-spec foo(integer()) -> integer()
; (atom()) -> atom().
Is there a way I can use this overloaded function's type in non-spec
contexts? Like I want to say bar/1 takes a function as an argument that has
a spec like foo/1 above.
I can think of the following options, but neither of them is exactly what I
want:
-spec bar(fun((integer() | atom()) -> integer() | atom())) -> ok.
%% Allows a function taking an integer and returning an atom.
-spec bar(fun((integer()) -> integer()) | fun((atom()) -> atom())) -> ok.
%% Allows fun erlang:atom_to_list/1, which doesn't work on integers at all.
Any better ideas? I'm sure Dialyzer can somehow represent internally the
overloaded function types, but is there a way I can write them myself?
Tanks,
Daniel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20170123/7a72b15c/attachment.htm>
More information about the erlang-questions
mailing list