#Does Zig support Julia style multiple dispatch?

1 messages · Page 1 of 1 (latest)

main kelp
#

I found the linked article, and it did a great job of showing how one can implement "closed multiple-dispatch", i.e. you can make a function that specializes to an implementation based on all the types in a function call, rather than just the first. As far as I understood from the linked article, dispatching on implementations within your module is possible, but then the author speculates on what would it take for
Open Multiple Dispatch, where others can define implementations of your function for their types. Does that exist in the Zig world?

https://www.scattered-thoughts.net/writing/open-multiple-dispatch-in-zig/

south vapor
#

you normally do this via struct methods. std.fmt is an example in that it specializes on stuff like u32, slices, floats, strings, but you can also pass in any struct that has a fmt() method which accepts the right args.

main kelp
#

Oh interesting

elder ember
#

It is possible to define something like an exported dispatch table within a module. This table should contain matching patterns based on which the call is resolved; it also should expose public API for consumers of this module to import it and add their own patterns. You would then perform calls through this table.