# Why don’t different non-optional keyword parameters specify multiple dispatches

**URL:** <https://discourse.julialang.org/t/why-don-t-different-non-optional-keyword-parameters-specify-multiple-dispatches/54500>\
**Category:** General Usage\
**Tags:** question\
**Created:** [February 3, 2021, 12:11am UTC](https://discourse.julialang.org/t/why-don-t-different-non-optional-keyword-parameters-specify-multiple-dispatches/54500 "2021-02-03T00:11:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![frankwswang](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/frankwswang/32/18561_2.png) [@frankwswang](https://discourse.julialang.org/u/frankwswang)\
**Post date:** [February 3, 2021, 12:11am UTC](https://discourse.julialang.org/t/why-don-t-different-non-optional-keyword-parameters-specify-multiple-dispatches/54500/1 "2021-02-03T00:11:07Z")

</div>

```julia
julia> foo(a; b, d="d", e="e") = (@show a b d e)
foo (generic function with 1 method)

julia> foo(a; m, d="d", e="e") = (@show a m d e)
foo (generic function with 1 method)

julia> foo(a; b, c, d="d", e="e") = (@show a b c d e)
foo (generic function with 1 method)

```

Is there a particular reason why this doesn’t work? I assume if the keyword argument does not have a default value, there shouldn’t be any ambiguity to choose which method to call?

Thank you!

---

<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:** [February 3, 2021, 1:18am UTC](https://discourse.julialang.org/t/why-don-t-different-non-optional-keyword-parameters-specify-multiple-dispatches/54500/2 "2021-02-03T01:18:27Z")

</div>

Keyword parameters do not define dispatch (note that you have only one method there). You can however define default values for optional parameters:

[https://docs.julialang.org/en/v1/manual/functions/#Optional-Arguments](https://docs.julialang.org/en/v1/manual/functions/#Optional-Arguments)

---

<div class="post-metadata">

**Author:** ![frankwswang](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/frankwswang/32/18561_2.png) [@frankwswang](https://discourse.julialang.org/u/frankwswang)\
**Post date:** [February 3, 2021, 3:02am UTC](https://discourse.julialang.org/t/why-don-t-different-non-optional-keyword-parameters-specify-multiple-dispatches/54500/4 "2021-02-03T03:02:43Z")

</div>

Sorry, I think maybe I haven’t conveyed my question clearly enough. My question is more like “why don’t different keyword parameters specify multiple dispatches”.

If they are optional parameters I can understand because we would encounter cases where the number and the types of the required (position) arguments are the same, which creates ambiguity for which method to call.

However, if those keyword arguments are not optional parameters, that means apart form passing additional variable names to pair with the arguments’ value, they “should” be no different from (position) arguments.

As for (position) arguments, we don’t need to define a specific type of each argument to form multiple dispatches, just the number of arguments is enough:

```julia
julia> g(a) = nothing
g (generic function with 1 method)

julia> g(a, b) = nothing
g (generic function with 2 methods)

```

I would like to know the language design philosophy behind this decision.

---

<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:** [February 3, 2021, 9:47am UTC](https://discourse.julialang.org/t/why-don-t-different-non-optional-keyword-parameters-specify-multiple-dispatches/54500/5 "2021-02-03T09:47:12Z")

</div>

I cannot help with the explanation of why exactly is that. But you can of course use this pattern:

```julia
f(a;b,c=1) = f(a,b,c)
f(a,b,c) = ...

```

To create and use methods associated with those optional or not keyword parameters.

---

<div class="post-metadata">

**Author:** ![frankwswang](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/frankwswang/32/18561_2.png) [@frankwswang](https://discourse.julialang.org/u/frankwswang)\
**Post date:** [February 3, 2021, 4:45pm UTC](https://discourse.julialang.org/t/why-don-t-different-non-optional-keyword-parameters-specify-multiple-dispatches/54500/6 "2021-02-03T16:45:50Z")

</div>

Cool! Thanks!
