<div dir="ltr">sure macro would work fine:<div><br></div><div><div>-define(MY_F_T, (list(),atom())-> boolean()).</div><div>-define(MY_F_T(Name), -spec Name?MY_F_T).</div><div><br></div><div>?MY_F_T(foo).</div><div><br></div><div>-spec hfoo(F) -> ok when F :: fun(?MY_F_T).</div></div><div><br></div><div>also this could be made more general by adding:</div><div><br></div><div><div>-define(FUN_SPEC(Name, Spec), -spec Name Spec).</div><div><br></div><div>?FUN_SPEC(foo,?MY_F_T).</div></div><div><br></div><div>but this is starting to be ugly and unreadable</div><div>in general i strongly dislike macros in any language but ... </div><div><br></div><div>it would bi nice if this could be done through spec like: </div><div><br></div><div>-spec foo :: my_f().</div><div><br></div><div>this is clean </div><div><br></div><div>but thanks for help i will try to see how solutions with macros works in my code base until some other solution comes by. </div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Oct 23, 2016 at 1:01 AM, Kenneth Lakin <span dir="ltr"><<a href="mailto:kennethlakin@gmail.com" target="_blank">kennethlakin@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On 10/22/2016 03:43 PM, Karlo Kuna wrote:<br>
> sure dialyzer will report error but callback functions are just one<br>
> motivation, for me the first example is far more important<br>
> as it reduces spec duplication which is annoying and not very expressive<br>
> IMHO.<br>
<br>
</span>Oh, drat. Right. You want to be able to vary the names of the function.<br>
You probably already thought about this, but how about a macro?<br>
<br>
-define(MY_F_SPEC(Fun), -spec Fun(list(),atom())->boolean())<wbr>.<br>
<br>
?MY_F_SPEC(foo).<br>
foo(L, A) -> true.<br>
<br>
?MY_F_SPEC(bar).<br>
bar(L, A) -> false.<br>
<br>
<br>
<br>______________________________<wbr>_________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/<wbr>listinfo/erlang-questions</a><br>
<br></blockquote></div><br></div>