|
Re: Five-minute Multimethods in Python
|
Posted: Apr 8, 2005 10:52 PM
|
|
I implemented a similar interface for multimethods recently, but it was a little more elaborate. I don't think this multimethod syntax is very Pythonic: when the reader sees foo(a,b), the reader expects a function call, not a method call. To my eyes, (a,b).foo() would be a more transparent syntax for multimethods; it's clear that foo is dispatching on the types of both a and b. On the other hand, it's ugly, and incompatible with Python as it stands now (an implementation would have to look something like DispatchOn(a,b).call('foo')). A compromise might look like a.foo(b), where it's clear that a method call is occuring, even if it isn't clear that it's dispatching on the type of b. It's also possible to implement it, although it's limited to pure Python classes.
Luckily, I haven't yet encountered a situation where I needed multimethods, so I'll stick with single dispatch.
|
|