Closed KlausC closed 4 years ago
While the method dispatch does not make use of the argument types of the keyword arguments, nevertheless the presence of those arguments make a different interface. Why should the designer of an interface not require, that a certain kwarg is supported by a method?
The hasmethod
method properly checks for the existence of keywords. I made a simple change to the software to support that.
Use case:
an interface description for AbstractArray
types could well request
@implement ArrayTrait by sum(; dims)
in order to force the implementor to provide sum(::ArrayTrait, a::AbstractArray; dim)
.
Interesting example. There's a little bit of a hurdle here though. For positional arguments, we just check the type for conformance. For keyword arguments, we would have to check the name as well.
For keyword arguments, we can currently only check for the names, not for the argument types. That is a restriction of hasmethod
. As I said, I made already an implementation of that. I had to store the keyword argument names in Contract
and use them in check
.
I guess that's better than nothing. It's not rigorous enough however. Maybe the hasmethod
function should be improved...
Just go ahead when you're ready for submit a PR. I would be happy to review and bring the new feature in.
Fixed by #33
Keyword arguments are not supported
This is actually a limitation with Julia itself because keyword arguments are not considered for dispatch. I also wonder how useful it would be… Can you share a use case for this if you happen to have one?