A polyglot's guide to multiple-dispatch (2016)

(eli.thegreenplace.net)

56 points | by andsoitis 4 days ago ago

12 comments

  • Panzerschrek 3 hours ago ago

    As I know C++ now allows multiple dispatch for std::variant: https://en.cppreference.com/w/cpp/utility/variant/visit2.htm....

    And std::variant is now a better choice for cases like in the article above, where previously inheritance was used to represent a closed set of possible subtypes.

    • maattdd 2 minutes ago ago

      TIL that std::visit supports multiple variants. How new is that ?

    • RossBencina an hour ago ago

      Where "now" means C++17 or C++20 depending on whether or not you understand what INVOKE<R> semantics are?

  • gobdovan 7 hours ago ago

    This is a nice illustration of the expression problem, which the article itself points out toward the end. Multiple dispatch is a language-level way to solve it. Crafting Interpreters [1] has a very approachable Java-based chapter that also covers these patterns in detail.

    [0] https://en.wikipedia.org/wiki/Expression_problem

    [1] https://craftinginterpreters.com/representing-code.html

  • fungiblecog 5 hours ago ago

    if only programmers cared about functionality as much as syntax we'd be living in a lisp heaven

    • 3cats-in-a-coat 5 hours ago ago

      You need some sort of critical majority that cares about deeper aspects of whatever (over superfice) or else everyone focuses on superfice, as that's what all the public debates are about.

      But lacking that, lisp could improve its syntax (did that, BTW not hard, just added some containers and a few standard infix operators, which all compile to lists).

  • ur-whale 2 hours ago ago

    Would have been nice to mention that it's one thing that Julia seem to have gotten right.

  • lisper 8 hours ago ago

    Cue the smug Common Lisp weenies...

    Oh, wait, that's me :-)