# Omitting type parameters on dispatch: accepted or implementation detail?

**URL:** <https://discourse.julialang.org/t/omitting-type-parameters-on-dispatch-accepted-or-implementation-detail/65552>\
**Category:** General Usage\
**Tags:** multidispatch\
**Created:** [July 30, 2021, 1:34pm UTC](https://discourse.julialang.org/t/omitting-type-parameters-on-dispatch-accepted-or-implementation-detail/65552 "2021-07-30T13:34:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [July 30, 2021, 1:34pm UTC](https://discourse.julialang.org/t/omitting-type-parameters-on-dispatch-accepted-or-implementation-detail/65552/1 "2021-07-30T13:34:38Z")

</div>

I am unsure if omitting additional type parameters on dispatch is an accepted and stable language behavior, or if it should be avoided, meaning doing things like this:

```julia
julia> using StaticArrays

julia> f(x::SVector{3}) = 3
f (generic function with 1 method)

julia> f(x::SVector{2}) = 2
f (generic function with 2 methods)

julia> x = rand(SVector{3,Float64});

julia> f(x)
3

julia> x = rand(SVector{2,Float64});

julia> f(x)
2

```

instead of being exhaustive and using:

```julia
julia> f(x::SVector{3,T}) where T = 3
f (generic function with 2 methods)

```

The first option of course works, but should we rely on that?

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [July 30, 2021, 1:53pm UTC](https://discourse.julialang.org/t/omitting-type-parameters-on-dispatch-accepted-or-implementation-detail/65552/2 "2021-07-30T13:53:05Z")

</div>

> [@lmiq](#):
>
> I am unsure if omitting additional type parameters on dispatch is an accepted and stable language behavior

Yes.

From [the manual](https://docs.julialang.org/en/v1/manual/types/#Parametric-Types): “Type parameters may be omitted when they do not need to be referenced or restricted.”

(The manual could be a lot more explicit about this, however — it might be good to add a subsection on omitting type parameters.)

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [July 30, 2021, 2:31pm UTC](https://discourse.julialang.org/t/omitting-type-parameters-on-dispatch-accepted-or-implementation-detail/65552/3 "2021-07-30T14:31:30Z")

</div>

It’s fine in dispatch (i.e. method arguments), but don’t (by accident) use those incompletely typed structs (or aliases for them) in type definitions, as [noted in this discourse post](https://discourse.julialang.org/t/type-instability-with-static-matrices-when-full-size-not-given/63079). You’ll induce type instability in the calling code when accessing those fields.
