tk3369 / BinaryTraits.jl

Can do or not? It's easy. See https://tk3369.github.io/BinaryTraits.jl/dev/
MIT License
51 stars 3 forks source link

@implement does not support keyword arguments #27

Closed KlausC closed 4 years ago

KlausC commented 4 years ago

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?

KlausC commented 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).

tk3369 commented 4 years ago

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.

KlausC commented 4 years ago

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.

tk3369 commented 4 years ago

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.

tk3369 commented 4 years ago

Fixed by #33