# Syntactic sugar for many arguments with same type annotation but separately dispatchable?

**URL:** <https://discourse.julialang.org/t/syntactic-sugar-for-many-arguments-with-same-type-annotation-but-separately-dispatchable/26249>\
**Category:** General Usage\
**Tags:** type, syntax\
**Created:** [July 11, 2019, 11:37am UTC](https://discourse.julialang.org/t/syntactic-sugar-for-many-arguments-with-same-type-annotation-but-separately-dispatchable/26249 "2019-07-11T11:37:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon32405968](https://avatars.discourse-cdn.com/v4/letter/a/57b2e6/32.png) [@anon32405968](https://discourse.julialang.org/u/anon32405968)\
**Post date:** [July 11, 2019, 11:37am UTC](https://discourse.julialang.org/t/syntactic-sugar-for-many-arguments-with-same-type-annotation-but-separately-dispatchable/26249/1 "2019-07-11T11:37:17Z")

</div>

Is there a syntactic sugar for a function where the arguments must all have a type T\<:SomeType, but each one could be a different type?

What I want to do might be clearer by example. So at the moment I might write a function like the following:

```julia

function afunk(arg1::T1, arg2::T2, arg3::T3) where T1<:Real where T2<:Real where T3<:Real
    ...
end

```

But I was wondering if there is a way to group those, something like:

```julia
function afunk(arg1::T1, arg2::T2, arg3::T3) where T1,T2,T3<:Real
    ...
end

```

(The latter syntax doesn’t work, just trying to demonstrate approximately what I’m after in case it is not clear.)

It might not seem that useful from the above example, but for my preference, it might stop me using a type alias like suggested in the following discussion as it would keep my function signatures neat and readable:

> [@Aliases for Union{T, Nothing} and Union{T, Missing}?](https://discourse.julialang.org/t/aliases-for-union-t-nothing-and-union-t-missing/15402/26):
>
> Given that the API of some functions in Julia now gives nothing if no sensible output exist, i.e. julia\> tryparse(Float64, "a") julia\> findfirst(==(3), [1, 2]) there was a proposal to create a few ? based syntactic sugar to work with nothing [https://github.com/JuliaLang/julia/issues/26303](https://github.com/JuliaLang/julia/issues/26303). If that happens, then the T? notation would be more consistent for nothing than missing.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [July 11, 2019, 1:39pm UTC](https://discourse.julialang.org/t/syntactic-sugar-for-many-arguments-with-same-type-annotation-but-separately-dispatchable/26249/2 "2019-07-11T13:39:57Z")

</div>

I don’t think there is a shorthand for this purpose. You have to spell out all the types and can’t combine `<:` relations. If you are not using `T1` etc, you can of course just use

```julia
function afunk(arg1::Real, ...

```

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [July 11, 2019, 2:39pm UTC](https://discourse.julialang.org/t/syntactic-sugar-for-many-arguments-with-same-type-annotation-but-separately-dispatchable/26249/3 "2019-07-11T14:39:18Z")

</div>

Adding on to this, you can follow @Tamas_Papp’s suggestion and then, if you still need to refer to the types of the arguments inside the function, you can do it with `typeof()` which should still not introduce any overhead:

```julia
julia> function f(a1::Real, a2::Real)
         T1 = typeof(a1)
         println(T1)
       end
f (generic function with 1 method)

julia> f(1.0, 2)
Float64

```
