[erlang-questions] is it possible to reuse a "-type" specification for a function in a "-spec" ?
Marco Molteni
marco.molteni@REDACTED
Thu Jul 28 21:35:21 CEST 2016
> On 28 Jul 2016, at 07:25, Kostis Sagonas <kostis@REDACTED> wrote:
>
> On 07/20/2016 10:21 PM, Marco Molteni wrote:
[..]
>> I would like to write something like:
>>
>> -spec my_cb :: decider().
>> my_cb(X, Tree) -> ...
>>
>> Is there a way?
>
> Yes, an ugly one, using macros.
>
> I would not recommend using that option though.
Ah, I see, and I see why you don't recommend it...
> Kostis
>
> PS. Some of the duplication in your example, can be avoided in a nice way by giving names to types. For example, you can define:
>
> -type node_rec() :: #node{}.
> -type decider_ret() :: reject | accept | continue.
> -type decider_fun() :: fun((pos_integer(),node_rec()) -> decider_ret()).
I though of something along these lines. So this is the best that can be done, OK.
thanks for your answer!
marco.m
More information about the erlang-questions
mailing list