[erlang-questions] [Dialyser] Type parametrized behaviours

Kostis Sagonas <>
Thu Apr 26 10:23:31 CEST 2012


On 04/26/2012 09:26 AM, Francesco Mazzoli wrote:
>> The first thing I think is that you have not fully understood the need
>> for having both a -callback and a -spec. In the general case, the
>> behaviour module needs to have a way to define what the callback module
>> *can* have as implementation of callbacks, not what it *should* have as
>> its implementation. For example, it's perfectly ok for the behaviour
>> module to say that there needs to be a callback function f/1 which can
>> return 'foo' and 'bar' and for the callback module to implement a
>> function that just returns 'bar'.
>
> By the way, I had overlooked this part and I don't see why you get this
> impression, I do acknowledge the possibility and the usefulness of
> narrowing the type via -specs in the implementing module (in fact, I do
> acknowledge that is already a solution to our problem, albeit a very
> ugly one).

Note that "ugly" is a subjective word.  I guess that qualifying it with 
"very" makes it... very subjective ;)

>> So, we do need both these attributes
>> since they serve different purposes. This also means that the "header
>> file approach" does not work / is not flexible enough in general.
>
> True, but I'd argue that this wouldn't/shouldn't happen often in the
> general case, given that the interface given to the user is the one of
> the behaviour -callbacks, and implementing functions with narrower
> arguments types will probably leads to breakage. I could see the
> usefulness of narrowing the result types, but still is not something
> that I'd do often.

I am not sure what your point is.  Just because this is something you 
(and perhaps many others, myself included) do not do that often, does 
not mean that Erlang does not need a mechanism that is general enough to 
allow them to do it, if they want/need to.

All I tried to argue in that part of my post is that the distinction 
between specifications of allowed callbacks (-callback attributes in the 
behaviour module) and actual implementations of these callbacks (-spec 
attributes in the callback module) is a general enough mechanism that 
serves this purpose.  I am sorry if you find it very ugly in your 
particular situation.  Perhaps others may find it ugly if Erlang gets 
extended with both a general and some less general mechanism to solve 
the same problem depending on the situation.  Think about it...

Enough on this. I need to digest at some point Matthew's mail which 
provides some more concrete information about what may still be missing 
from callbacks.

Kostis



More information about the erlang-questions mailing list