[erlang-questions] Type specifications for modules implementing a specific behaviour

Ali Sabil <>
Mon Dec 19 17:07:31 CET 2016


I don't think this is supported by dialyzer today, but it would indeed be a
very valuable addition. It's a feature I would really appreciate myself.

On Mon, Dec 19, 2016 at 4:40 PM Sölvi Páll Ásgeirsson <>
wrote:

> Hi
>
> (sorry if this is a duplicate, but I sent this message to the list
> last week, before subscribing to it, cannot find it anywhere and
> assumed it went to the bitbucket)
>
> I've searched, but I haven't found anything and I'm afraid of what I'm
> asking is impossible, but I thought I'd ask here as well.
>
> Is there a way for us to say that a type spec is describing a module
> that should implement a specific behaviour?
>
> That is,  I want to do something like the following:
>
>    -module(foo).
>    -callback foo(bar) -> quux.
>
> Then I'll have a concrete implementation of this:
>
>    -module(bar).
>    -behaviour(foo).
>    foo(bar) -> quux.
>
> In the third module, I'd like to spec a record so that I can state
> that a certain field of the record
> should contain an atom which is the name of a module implementing a
> behaviour:
>
>    -module(quux).
>    -record(state, { callback_mod = bar :: behaviour(foo) }).
>
> I'd then of course like Dialyzer to tell me if something is wrong.
> Can we do something like this?  If not, would it be extremely
> difficult to add support for this?  Where could I start?
>
> Thanks alot
> Sölvi Páll Ásgeirsson
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20161219/86a190a4/attachment.html>


More information about the erlang-questions mailing list