I have been implementing a new type of array which is just a normal array except the content is fetched in the background and everything about it is the same as a normal array including access etc.
I call this Array the Ghost Array. For example I have been defining functions like
getindex(a::GhostArray, I) = getindex(materialize(a), I)
So I am overloading the getindex method which is fine. But I want GhostArray to work with hundreds of methods and the pattern for doing so is the same which is.
So I want for all
fn, do the above. But there is no way to know all possible
fn. And people can always define more
fns. Also there are
fns where GhostArray is not the first argument. I want to “overtake” them too.
One way I thought would be to have some Trojan horse types that can take over the any function and replace itself with
I call these types the Trojan horse types, because they go in and try to take over.
I don’t think this can be done in Julia yet. I know of Cassette.jl but I think that would require the code to be run in a context so can’t deal with all possible functions (my understanding might be off here).
I would highly appreciate if anyone can point to programming language research that already has this idea discussed and researched this and if there are languages already implementing this.
Would be nice if something like this is possible in Julia though. Or maybe it is already! Please enlighten me!