[erlang-questions] [Dialyser] Type parametrized behaviours
Thu Apr 26 09:26:29 CEST 2012
> 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
> 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.
More information about the erlang-questions