Short-hand for defining methods

Is there a way to define something like f(a::AbstractArray, b::AbstractArray, ...) without having to repeat the type each time?
I know I could do f(a::T, b::T, ...) where T <: AbstractArray but that would restrict all the arguments to be of the same type.

f(a,b,...). As an added bonus you get duck typing for free.

3 Likes

You could do something like

const AA = AbstractArray
f(a::AA, b::AA) = a .+ b

or

let T = AbstractArray
    global f(a::T, b::T) = a .+ b
end
4 Likes

Thanks for the suggestions. @ChrisRackauckas’ is very insightful :stuck_out_tongue: I was thinking more of a metaprogramming way, which I don’t know much about.