Remove eltype parameter from AbstractArray and use IteratorEltype instead #39626
Labels
arrays
[a, r, r, a, y, s]
breaking
This change will break code
design
Design of APIs or of the language itself
needs decision
A decision on this change is needed
speculative
Whether the change will be implemented is speculative
traits
Traits, sometimes called Tim Holy Traits
Background:
There seems to be a preponderance of theoretical AbstractArrays (roughly, a bunch of things arranged in a hypercube) without eltypes:
Iterator.map
objectsThe reason these things don't have an eltype is fundamentally because Julia is a dynamic language and return types aren't really supposed to exist. That is, you can't really know the type of the result of applying a function (like the mapping function, or
view
for array slices) until you actual do it.The problem is, none of the the theoretical AbstractArrays can inherit any of the methods defined for AbstractArrays, which means they either have to duplicate a whole bunch of machinery (like the broadcasted objects) or just not have the same super powers (like the
Iterator.map
s). I've been thinking about this for a while; see #34196 and #35095 for context.I really like @andyferris 's idea in #32310 (comment) as a simple solution. The idea if I understand correctly is to remove the eltype type parameter from AbstractArray, and instead, unless you already know it exists, access the
eltype
only after having checked theIteratorEltype
trait first.The advantages I see are:
IteratorEltype
, this would just make it more consistent.The disadvantages I see are:
IteratorEltype
first.I had a crack at messing around with the code in src to make a PR and realized pretty quickly I was out of my depth because I don't know much C (and obtuse abbreviated names don't help much). If someone figures that out though, I could do the Julia parts (updating Julia code and tests). I suppose this is likely too big of a change for 1.0?
Sorry if I wrote too much...I figure too much is better than too little though.
The text was updated successfully, but these errors were encountered: