Has anyone given some thought how to work with collections of objects that have a (set of) trait(s)? How to create, maintain, iterate… What would a Base.iterate
extension look like?
An example of something concrete would help clarify this question.
Well, I think one of the points of having traits is that the compiler can figure out types at compile time. However, that seems to me much more difficult when objects possessing a given trait are elements of an array. The array must be heterogeneous (I think), which makes dispatch dynamic. Am I wrong?
Sure, arrays without concrete element types will be suboptimal generally for compile-time dispatch, including traits.
I was asking about a concrete problem to see if there is a better way to formulate a solution (cf XY problem).
Right you are.
I wonder if https://github.com/rdeits/ConcreteInterfaces.jl might be helpful? FWIW I’ve never actually used it in a serious project, but I keep thinking it might be helpful.
Nice! That seems to be precisely what I was asking about. Thanks.