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

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?

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

2 Likes

what is meant by static typed?

Multiple dispatch is possible within a statically typed language. E.g., there was a proposal for adding multiple dispatch to C++. 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.

9 Likes