[erlang-questions] type specification of functions with same signature
Sun Oct 23 09:58:47 CEST 2016
sure macro would work fine:
-define(MY_F_T, (list(),atom())-> boolean()).
-define(MY_F_T(Name), -spec Name?MY_F_T).
-spec hfoo(F) -> ok when F :: fun(?MY_F_T).
also this could be made more general by adding:
-define(FUN_SPEC(Name, Spec), -spec Name Spec).
but this is starting to be ugly and unreadable
in general i strongly dislike macros in any language but ...
it would bi nice if this could be done through spec like:
-spec foo :: my_f().
this is clean
but thanks for help i will try to see how solutions with macros works in my
code base until some other solution comes by.
On Sun, Oct 23, 2016 at 1:01 AM, Kenneth Lakin <kennethlakin@REDACTED>
> On 10/22/2016 03:43 PM, Karlo Kuna wrote:
> > sure dialyzer will report error but callback functions are just one
> > motivation, for me the first example is far more important
> > as it reduces spec duplication which is annoying and not very expressive
> > IMHO.
> Oh, drat. Right. You want to be able to vary the names of the function.
> You probably already thought about this, but how about a macro?
> -define(MY_F_SPEC(Fun), -spec Fun(list(),atom())->boolean()).
> foo(L, A) -> true.
> bar(L, A) -> false.
> erlang-questions mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the erlang-questions