Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It looks like singledispatch is still relatively new, so it feels like that might not yet be representative either?

But the bigger distinction would be that Julia uses multiple dispatch, not just single, so the argument order does not dictate the dispatch capabilities. And it is little things like that which may sound trivial[1], but add up to be less effort to use (since there isn’t any other kind of function), which then also translated into being easier to optimize and run fast.

It may be hard to show this feature advantage in a single demo, as the advantage to this is better composability of multiple nouns and verbs in the language, particularly when pulling from multiple sources. Thus, Julia doesn’t need a different sin and np.sin function, for example, as the one function is already prepared to work for either caller.

[1] compare also len vs __len__ and __radd__ vs __ladd__ vs +, a hidden property distinction which doesn’t need to exist in Julia

Disclaimer: I work on Julia’s compiler team



Singledispatch is old, dates back to py2: https://docs.python.org/3/library/functools.html#functools.s...

I definitely agree that multiple dispatch is a lot harder :). But most of the examples in the article didn't need it, and it would have been appropriate I think to show equivalent code in Python. All that article did was make me think the author didn't know Python very well.

There are several libraries for multiple dispatch too, for e.g. https://github.com/wesselb/plum


Python's single dispatch just means that if I do `foo.bar()`, the meaning of bar depends on the type of `foo`. So that is not recent, but a core part of the language.

Another difference to Python is that you can't add new methods post-hoc to types in Python. That's a big problem, but this has nothing to do with single/multiple dispatch. E.g. Rust has single dispatch but allows post-hoc methods.


> you can't add new methods post-hoc to types in Python

Unless I'm misunderstanding what that means, you totally can:

    >>> class Foo:
    ...     def bar(self):
    ...         return 3
    ...
    >>> foo = Foo()
    >>> foo.bar()
    3
    >>> Foo.baz = lambda self: 6
    >>> foo.baz()
    6
    >>>


So just to clarify since it perhaps wasn't clear, I'm talking about singledispatch from the standard library: https://docs.python.org/3/library/functools.html#functools.s...


> Another difference to Python is that you can't add new methods post-hoc to types in Python.

Yes, you can. Heck, you can post-hoc add new methods to instances in python, too.


> But the bigger distinction would be that Julia uses multiple dispatch, not just single,

Multiple dispatch is just (or, at any rate, equivalent in function to) single dispatch with tuple types.

But, Julia does things like triangular dispatch, but the advantage there is narrower.


Is there any single dispatch language that lets you define multiple methods for a function of a tuple depending on the type of its elements?




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: