7 ms·
Multiple dispatch is not too different to method overloading, so you could start there for comparable examples, maybe in programming languages you are more fami
by DougBTX 6y ago
Multiple dispatch is not too different to method overloading, so you could start there for comparable examples, maybe in programming languages you are more familiar with: https://en.wikipedia.org/wiki/Function_overloading#Rules_in_function_overloading https://en.wikipedia.org/wiki/Function_overloading#Rules_in_...
Bag of functions isn't a bad way to think about it, even for Julia. In some languages, only the name of the function determines which function is called. In others, the number of arguments is used too, so eg foo/1 and foo/2 may be different functions. In Julia, the types matter too, so foo(::Int) and foo(::String) are different functions ("methods" in Julia terminology), and which is used is based on the type of the argument, rather than the number.
That's where the magic in Julia happens, as if you define a function foo(x), without specifying any types, then the specific functions that foo call will only be determined once the type of the arguments to foo are known. But once they are known, that type information can ripple all the way down, picking up the specific implementation for each function depending on the actual types used.