[erlang-questions] dialyzer and behaviours

Daniil Churikov ddosia@REDACTED
Wed Jul 16 15:55:12 CEST 2014


Thank you Sean for your response. The problem is, how to tell to dialyzer
that `my_db:create(Mod, Vals)'
is accepts only Mod's which implements `-behaviour(my_db)'? and not an
arbitrary atom?


2014-07-16 17:41 GMT+04:00 Sean Cribbs <sean@REDACTED>:

> Your example will work if you are implementing some other module which
> uses my_db as its behavior:
>
> -module(db_impl).
> -behaviour(my_db).
> -export([table/0]).
>
> table -> ["hello, world"].
>
>
> On Wed, Jul 16, 2014 at 7:56 AM, Daniil Churikov <ddosia@REDACTED> wrote:
>
>> %% I apologize if you get this message second time, but initially I
>> posted it through google-groups
>> %% interface and discovered that it is not replicated to this mailing
>> list.
>>
>> Is there any way to write a spec for dialyzer that will tell that I
>> expect module of certain behaviour?
>>
>> Simplified example:
>>
>> -module(my_db)
>>
>> -callback table() -> iolist().
>>
>> %% Instead of `Mod :: atom()' I want something that will reflect that only
>> %% modules which implements `my_db' behaviour are allowed.
>> -spec create(Mod :: atom(), Vals :: [iolist(), ...]) -> iolist().
>> create(Mod, Vals) ->
>>     Table = Mod:table(),
>>     ["INSERT INTO ", Table, " VALUES (", string:join(Vals, ", "), ");"].
>>
>> _______________________________________________
>> erlang-questions mailing list
>> erlang-questions@REDACTED
>> http://erlang.org/mailman/listinfo/erlang-questions
>>
>>
>
>
> --
> Sean Cribbs <sean@REDACTED>
> Software Engineer
> Basho Technologies, Inc.
> http://basho.com/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20140716/f22e60bb/attachment.htm>


More information about the erlang-questions mailing list