This is a fairly concrete question: the user passes in a type AA <: AbstractArray and I want to make a concrete instantiation of this type which contains some specified data, e.g. [1,2,3]. Here is the best I’ve come up with using the interface specified here: Interfaces · The Julia Language
arr = similar(AA, 3)
arr .= 1:3
However, this will not work if e.g. arr is mutable (whereas in theory this makes sense for immutable arrays too).
Some special cases of this problem of instantiating an array type with concrete data are covered by e.g. the zeros and ones functions (although they are only defined in Base for Array so I’m not sure if I can even assume their existence…), but is there a general way of solving this?
For many array types, this only makes limited sense. For example, if AA in your example is an OffsetArray, or a KeyedArray, then you don’t have any information on the offset or axis keys.
So, the question is what kind of array types do you have in mind? If they implement similar(T, ...), then your original solution would work and always return a mutable array (not always of the specified type, eg for static arrays).