Apologies if this has already been discussed before. I couldn’t find an issue on GitHub or a discussion on Discourse that seems to address this (though I feel like I remember seeing one before…).
It would be really nice to have type constructors in Julia, and by that, I mean higher order type constructors. For example, it would be nice to be able to do this:
function foo(data::A{T}) where {T,A<:AbstractArray}
# do something with type A
end
This provides access to the base UnionAll
type of data
, which is otherwise quite difficult (maybe impossible?) to get without using inttrospection.
One can then use the type A
to construct new parametric types like A{C}
. You can kind of think of this as a generalization of what similar
does for Arrays to any parametric type (though one must still make assumptions about the constructor, of course).
This is a very common pattern in functional programming languages and is really quite powerful.
I don’t know much about the internals of Julia’s compiler, and I’m guessing there’s probably some limitations that might make this difficult or impossible to implement, but I wanted to at least throw the idea out there, in case it hasn’t been discussed before.
If there is an existing clever way to accomplish this that I’m not aware of, please let me know!