[erlang-questions] type specification of functions with same signature
Karlo Kuna
kuna.prime@REDACTED
Sat Oct 22 20:48:53 CEST 2016
let's say we have two function specifications:
-spec foo(list(), atom()) -> boolean().
and
-spec bar(list(), atom()) -> boolean().
is it possible to do something like this:
-type my_f() :: fun ((list(),atom())->boolean()).
and then:
-spec foo :: my_f().
-spec bar :: my_f().
i couldn't find a way of doing this
this would remove code duplication in type specifications
also i think it would make code *much* clearer
for example (bad one):
in higher order function
%% module1.erl
-spec hfoo(T,F) -> ok when
T :: any(),
F :: my_f().
-export_type([my_f/0]).
%% module2.erl
-spec my_algorithm :: module1:my_f().
here i can express with type specification that i'm implementing function
that will be compatible with module1:hfoo/2 and possible others
is there way to achieve this in current erlang and if not are there any
plans to include something similar in future versions?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20161022/705e1892/attachment.htm>
More information about the erlang-questions
mailing list