JuliaLang/julia — pull request #7025 by tknopp (2014-05-29 07:11:42+00:00)
Title: RFC: Interface Prototype

This is prototype for the interface system outlined in #6975. The most important missing thing is the parse support that would need help from someone with experience in hacking the parser.

This PR adds three functions:
- `add_interface`: Adds an interface to the interface table (this is what should be called from the parser)
- `verify_interface`: Checks whether a type fulfills all interfaces
- `isinterface`: Returns if a function belongs to an interface (this is an internal function used by `showerror`)

Further, the PR modifies `showerror` to check if a function is an interface and then displays the error message.

The interface implementation can be used in two different ways. Either one implements the interface and the calls `verify_interface` to directly validate that the interface is fulfilled. Or one skips the last step and still gets a nice error message.

In action:

julia> abstract A
julia> type B <: A end
julia> Base.add_interface(A,:length)
julia> length(B())
ERROR: Type B has to implement length to be a subtype of A!
no method length(B)