<html>
  <head>
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
  </head>
  <body text="#330033" bgcolor="#FFFFFF">
    <div class="moz-cite-prefix">On 5/23/2013 12:14 AM, Antoine Pitrou
      wrote:<br>
    </div>
    <blockquote cite="mid:20130523091435.0dd5f61e@fsol" type="cite">
      <pre wrap="">On Thu, 23 May 2013 02:33:57 -0400
Devin Jeanpierre <a moz-do-not-send="true" class="moz-txt-link-rfc2396E" href="mailto:jeanpierreda@gmail.com"><jeanpierreda@gmail.com></a> wrote:
</pre>
      <blockquote type="cite" style="color: #000000;">
        <pre wrap=""><span class="moz-txt-citetags">> </span>On Thu, May 23, 2013 at 2:04 AM, Antoine Pitrou <a moz-do-not-send="true" class="moz-txt-link-rfc2396E" href="mailto:solipsis@pitrou.net"><solipsis@pitrou.net></a> wrote:
</pre>
        <blockquote type="cite" style="color: #000000;">
          <pre wrap=""><span class="moz-txt-citetags">> > </span>On Thu, 23 May 2013 12:12:26 +1000
<span class="moz-txt-citetags">> > </span>Nick Coghlan <a moz-do-not-send="true" class="moz-txt-link-rfc2396E" href="mailto:ncoghlan@gmail.com"><ncoghlan@gmail.com></a> wrote:
</pre>
          <blockquote type="cite" style="color: #000000;">
            <pre wrap=""><span class="moz-txt-citetags">> >> </span>The binary operators can be more accurately said to use a complicated
<span class="moz-txt-citetags">> >> </span>single-dispatch dance rather than supporting native dual-dispatch.
</pre>
          </blockquote>
          <pre wrap=""><span class="moz-txt-citetags">> ></span>
<span class="moz-txt-citetags">> > </span>Not one based on the type of a single argument, though.
</pre>
        </blockquote>
        <pre wrap=""><span class="moz-txt-citetags">> </span>
<span class="moz-txt-citetags">> </span>Why not?
<span class="moz-txt-citetags">> </span>
<span class="moz-txt-citetags">> </span>I'd expect it to look something like this:
<span class="moz-txt-citetags">> </span>
<span class="moz-txt-citetags">> </span>    @singledispatch
<span class="moz-txt-citetags">> </span>    def ladd(left, right):
<span class="moz-txt-citetags">> </span>        return NotImplemented
<span class="moz-txt-citetags">> </span>
<span class="moz-txt-citetags">> </span>    @singledispatch
<span class="moz-txt-citetags">> </span>    def radd(right, left):
<span class="moz-txt-citetags">> </span>        return NotImplemented
<span class="moz-txt-citetags">> </span>
<span class="moz-txt-citetags">> </span>    def add(left, right):
<span class="moz-txt-citetags">> </span>        x = ladd(left, right)
<span class="moz-txt-citetags">> </span>        if x is not NotImplemented:
<span class="moz-txt-citetags">> </span>            return x
<span class="moz-txt-citetags">> </span>        x = radd(right, left)
<span class="moz-txt-citetags">> </span>        if x is not NotImplemented:
<span class="moz-txt-citetags">> </span>            return x
<span class="moz-txt-citetags">> </span>        raise TypeError
<span class="moz-txt-citetags">> </span>
<span class="moz-txt-citetags">> </span>Then instead of defining __add__ you define an overloaded
<span class="moz-txt-citetags">> </span>implementation of ladd, and instead of defining __radd__ you define an
<span class="moz-txt-citetags">> </span>overloaded implementation of radd.
</pre>
      </blockquote>
      <pre wrap="">Well, I don't think you can say add() dispatches based on the type of a
single argument. But that may be a question of how you like to think
about decomposed problems.
</pre>
    </blockquote>
    <br>
    I suspect the point was not that add can be described as doing
    single dispatch (it can't), but rather that add could possibly be
    implemented in terms of lower-level functions doing single dispatch.
    If that was the point, perhaps the next level point is trying to be
    that single dispatch is a sufficient mechanism that can be augmented
    (as above) to handle more complex cases. Whether the above (which I
    think would need to use raise and try instead of return and if) is
    sufficient to handle such cases is not yet proven. The case Guido
    mention where radd is tried before add would seem to require a bit
    more complex logic than the above.<br>
  </body>
</html>