# Short-hand for defining methods

**URL:** https://discourse.julialang.org/t/short-hand-for-defining-methods/9707
**Category:** New to Julia
**Created:** [March 14, 2018, 3:38am UTC](https://discourse.julialang.org/t/short-hand-for-defining-methods/9707 "2018-03-14T03:38:39Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![amrods](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/amrods/32/2543_2.png) [@amrods](https://discourse.julialang.org/u/amrods)
#### Post date: [March 14, 2018, 3:38am UTC](https://discourse.julialang.org/t/short-hand-for-defining-methods/9707/1 "2018-03-14T03:38:39Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)
#### Post date: [March 14, 2018, 4:13am UTC](https://discourse.julialang.org/t/short-hand-for-defining-methods/9707/2 "2018-03-14T04:13:51Z")

</div>

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

---

<div class="post-metadata">

### Author: ![tkoolen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkoolen/32/1603_2.png) [@tkoolen](https://discourse.julialang.org/u/tkoolen)
#### Post date: [March 14, 2018, 5:03am UTC](https://discourse.julialang.org/t/short-hand-for-defining-methods/9707/3 "2018-03-14T05:03:00Z")

</div>

You could do something like

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

```

or

```julia
let T = AbstractArray
    global f(a::T, b::T) = a .+ b
end

```

---

<div class="post-metadata">

### Author: ![amrods](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/amrods/32/2543_2.png) [@amrods](https://discourse.julialang.org/u/amrods)
#### Post date: [March 14, 2018, 7:20am UTC](https://discourse.julialang.org/t/short-hand-for-defining-methods/9707/4 "2018-03-14T07:20:23Z")

</div>

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