# If Julia was static typed, how multiple dispatch would work?

**URL:** <https://discourse.julialang.org/t/if-julia-was-static-typed-how-multiple-dispatch-would-work/95529>\
**Category:** Internals & Design\
**Tags:** question, multiple-dispatch\
**Created:** [March 4, 2023, 6:16am UTC](https://discourse.julialang.org/t/if-julia-was-static-typed-how-multiple-dispatch-would-work/95529 "2023-03-04T06:16:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dylanxyz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dylanxyz/32/36646_2.png) [@dylanxyz](https://discourse.julialang.org/u/dylanxyz)\
**Post date:** [March 4, 2023, 6:16am UTC](https://discourse.julialang.org/t/if-julia-was-static-typed-how-multiple-dispatch-would-work/95529/1 "2023-03-04T06:16:03Z")

</div>

If Julia was a static typed language instead of dynamic typed, how would multiple dispatch work? It would be simple function overloading or something different? Instead of compiling the functions that are called during runtime, the compiler would be able to do that before executing the function (at compile time)? Would this make easier to compile julia programs to static binaries?

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [March 4, 2023, 6:20am UTC](https://discourse.julialang.org/t/if-julia-was-static-typed-how-multiple-dispatch-would-work/95529/2 "2023-03-04T06:20:28Z")

</div>

it would probably behave similarly to C++ templates, but Julia’s type system want really designed with static typing in mind.

---

<div class="post-metadata">

**Author:** ![xiaodai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xiaodai/32/15937_2.png) [@xiaodai](https://discourse.julialang.org/u/xiaodai)\
**Post date:** [March 4, 2023, 10:51pm UTC](https://discourse.julialang.org/t/if-julia-was-static-typed-how-multiple-dispatch-would-work/95529/3 "2023-03-04T22:51:47Z")

</div>

what is meant by static typed?

---

<div class="post-metadata">

**Author:** ![arch.d.robison](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/arch.d.robison/32/17699_2.png) [@arch.d.robison](https://discourse.julialang.org/u/arch.d.robison)\
**Post date:** [March 5, 2023, 1:52am UTC](https://discourse.julialang.org/t/if-julia-was-static-typed-how-multiple-dispatch-would-work/95529/4 "2023-03-05T01:52:03Z")

</div>

Multiple dispatch is possible within a statically typed language. E.g., there was a proposal for [adding multiple dispatch to C++](https://www.stroustrup.com/multimethods.pdf). That proposal describes how the work would be split between compile time and runtime, and some help from the linker.

I don’t know if there is a formal definition of “static binary”, so I’ll assume it means “includes all runtime instructions”, i.e. there will be no runtime code generation. I think the key property to compiling such static binaries is for the compiler to know at compile time (which is a concept foreign to Julia _semantics_):

- all types
- all function definitions
- names of all variables, both local and global

These allow “closed universe assumptions”, e.g. name lookup can be done at compile time, and all dispatch candidates are known at each call site. While more information on variables is nice to have, e,g. bounds on their run-time type, it’s not essential given that (by the first bullet) the compiler knows it’s one of the types that is known at compile time.
