[Python-Dev] PEP 443 - Single-dispatch generic functions (original) (raw)
Devin Jeanpierre jeanpierreda at gmail.com
Thu May 23 08:33:57 CEST 2013
- Previous message: [Python-Dev] PEP 443 - Single-dispatch generic functions
- Next message: [Python-Dev] PEP 443 - Single-dispatch generic functions
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Thu, May 23, 2013 at 2:04 AM, Antoine Pitrou <solipsis at pitrou.net> wrote:
On Thu, 23 May 2013 12:12:26 +1000 Nick Coghlan <ncoghlan at gmail.com> wrote:
The binary operators can be more accurately said to use a complicated single-dispatch dance rather than supporting native dual-dispatch. Not one based on the type of a single argument, though.
Why not?
I'd expect it to look something like this:
@singledispatch
def ladd(left, right):
return NotImplemented
@singledispatch
def radd(right, left):
return NotImplemented
def add(left, right):
x = ladd(left, right)
if x is not NotImplemented:
return x
x = radd(right, left)
if x is not NotImplemented:
return x
raise TypeError
Then instead of defining add you define an overloaded implementation of ladd, and instead of defining radd you define an overloaded implementation of radd.
-- Devin
- Previous message: [Python-Dev] PEP 443 - Single-dispatch generic functions
- Next message: [Python-Dev] PEP 443 - Single-dispatch generic functions
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]