Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Towards true duck-typing #35940

Closed
bramtayl opened this issue May 19, 2020 · 2 comments
Closed

Towards true duck-typing #35940

bramtayl opened this issue May 19, 2020 · 2 comments

Comments

@bramtayl
Copy link
Contributor

bramtayl commented May 19, 2020

Ok. So the fundamental motivating problem here is broadcasted objects, which have size and getindex methods, but not eltype and setindex! methods. That is, they implement 1/2 of the AbstractArray interface. A lot of methods defined for AbstractArrays, however, do not require eltype nor setindex!. For evidence of this, see #34196. So it would be nice if these methods could be automatically defined for broadcasted objects.

The fundamental problem is that labeling something as AbstractArray is, at least by the interface definition, simply asserting that it has four special methods (getindex, setindex!, eltype, and size). However, this information is contained only in the documentation, and not encoded into the language itself. So solving this problem requires having some way of addressing this information gap.

Therefore, I propose the following:

  1. All abstract types be required to define exactly what fundamental methods are required of them
  2. A way to harness this information during dispatch

I'm not sure of the best way to implement a solution, but I can suggest that solutions should avoid boolean hell. For an extended discussion of the topic of boolean hell, see #35095

Quack quack

@JeffBezanson
Copy link
Member

Duplicate of #6975. The feature described here is interfaces, not duck typing. You get duck typing just by removing type constraints from arguments.

@bramtayl
Copy link
Contributor Author

Yes, that issue is exactly what I was trying to describe!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants