I have a bunch of method signatures like this:
sig1 = Tuple{typeof(rrule), typeof(sum), AbstractArray{T, N} where N} where T<:Number
sig2 = Tuple{typeof(rrule), typeof(mean), AbstractArray{var"#s256", N} where {var"#s256"<:Real, N}}
...
Now I want to get similar signatures but without the first type parameter, i.e.:
Tuple{typeof(sum), AbstractArray{T, N} where N} where T<:Number
Tuple{typeof(mean), AbstractArray{var"#s256", N} where {var"#s256"<:Real, N}}
I tried to do it it in-place:
function remove_first_parameter(sig)
subsig = sig
# unroll UnionAll wrappers
while subsig isa UnionAll
subsig = subsig.body
end
subsig.parameters = Core.svec(subsig.parameters[2:end])
return sig
end
But it corrupts the method table, and deepcopy()
doesn’t work on types.
I managed to compose a function to remove first parameter like this:
remove_first_parameter(::Type{Tuple{T1, T2, T3}}) where {T1, T2, T3} = Tuple{T2, T3}
It works with sig2
which is a DataType
, but not with sig1
which is UnionAll
.
Is there a method which works with UnionAll
as well?