[erlang-questions] [Dialyser] Type parametrized behaviours

Stavros Aronis aronisstav@REDACTED
Tue Apr 24 21:36:19 CEST 2012


In this case you can leave generic definitions in the -callback attributes 
and write the fully specified specs in the callback module:

%% Behaviour module:
...
-callback step(State :: term()) -> NewState :: term().
...

%% Callback module:
...
-type state() :: #state{}.
...
-spec step(state()) -> state().
...

Dialyzer will check that your specs are subtypes of the corresponding 
callback attributes. What added benefit would you gain from your suggestion?

Stavros

On Tuesday, April 24, 2012 10:26:08 PM UTC+3, Francesco Mazzoli wrote:
>
> On 24/04/12 19:10, Stavros Aronis wrote:
> > Hi Francesco,
> >
> > Do you mean that after your update these types have to be moved within
> > the behaviour file itself? If this is the case, you could export them
> > using the "-export_type" attribute and then use them as remote types:
> > "behaviour_module:type_name()". You can use them in this way in both
> > specs and other -type definitions and at least Dialyzer won't have any
> > problem at all.
> >
> > Stavros
>
> No, that's not what I want.
>
> To give a small example of what I want to do, a behaviour might define
>
>     -callback step(state()) -> state().
>
> where `state()' is not define locally in the behaviour, but in each 
> implementing module.
>
> I hope I made myself more clear.
>
> Francesco.
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20120424/0cdc9988/attachment.htm>


More information about the erlang-questions mailing list