[erlang-questions] Using -spec for callbacks when defining behaviours
Wed Mar 17 15:08:52 CET 2010
On Wed, Mar 17, 2010 at 12:01, Mikael Karlsson <karlsson.rm@REDACTED> wrote:
> I understand that -spec (and -type) constructs may be used in include
> (.hrl) files and the module itself when specifying functions.
> Has there been any discussion on beeing able to use them in behaviour
> defining modules to specify the "callback" modules in more detail?
> When defining a behaviour today you "just" specify the function names and
> their arity with the behaviour_info/1 function.
> I think it would be good to be able to also specify the types of the
> arguments and their return type for the module implementing the behaviour.
> This would make a behaviour defining module closer to a interface
> specification and also decrease the depenencies of include files.
There are two issues here:
- attach the -spec to the callback functions. I think that a simple
way to do that is to have the module declaring the behaviour implement
even the callbacks (as dummy functions) and then type specs can be
attached to them. There might be problems with name conflicts, but I
don't think there are that many behaviours out there besides the
standard ones to be a problem. In the worst case, these dummy
functions could be put in a separate module.
- check that a module implementing a behaviour respects the declared
specs. This I let to the dialyzer team to work out :)
More information about the erlang-questions