4 ms·
Here's a good explanation of this technique: http://julien.danjou.info/blog/2013/python-3.4-single-dispatch-generic-function http://julien.danjou.info/blog/2013
by babarock 13y ago
Here's a good explanation of this technique: http://julien.danjou.info/blog/2013/python-3.4-single-dispatch-generic-function http://julien.danjou.info/blog/2013/python-3.4-single-dispat...
- ubertaco 13y agoNice! That's something I like about Haskell and Elixir: the ability to define behavior for a given case. Though it looks like that's constrained to type-based dispatch (a la Java method overloading). Is there any way to define for specific values?
- hyperpape 13y agoIf I read this article properly, there's nothing yet standardized, but there's a possibility of future development: http://lukasz.langa.pl/8/single-dispatch-generic-functions/ http://lukasz.langa.pl/8/single-dispatch-generic-functions/.
- bcoates 13y agoIf I understand the PEP right, this explanation is missing the part where it's only useful to extend abstract classes; python classes are open so you can just add a method to a concrete class to get single-dispatch if that's all you need. I don't think the example given needs generics at all.
- hyperpape 13y agoI had a hard time understanding the value of the idea from this as well. The link I gave made it a bit clearer to me.
- eurleif 13y ago>python classes are open so you can just add a method to a concrete class to get single-dispatch if that's all you need. Except then your method shares a namespace with all the other methods defined on the class, which is ugly, and can cause clashes.