[RFC/WIP] DuckDispatch.jl

I think I’ve seen mention of trait dispatch in Interfaces.jl in a couple places, but I can’t find it in the documentation. Can you provide an example of what trait dispatch looks like in Interfaces.jl?

A question for the community: When creating a method that dispatches a DuckType, the macro produces a generic method to intercept any call that match the number of arguments which does all the wrapping decision making before re-dispatching the wrapped arguments to the same function.

This means, if you try to @duck_dispatch a function from another package, you commit type piracy by creating a new method of f(arg1::Any, ...). The macro already checks to see if there is an existing method that would be overwritten, but it doesn’t do anything to make sure that the user owns the function.

Is documenting this behavior sufficient or should a programmatic check be added? If so, how would you even do that?

There is an implements function that returns a Bool if a trait is implemented

Or implemented_trait if you want to use Implemented or NotImplemented in dispatch.

2 Likes