[Python-3000] Fw: typeclasses, duck-typing
Ben.Young at risk.sungard.com
Ben.Young at risk.sungard.com
Thu May 11 17:27:15 CEST 2006
"Phillip J. Eby" <pje at telecommunity.com> wrote on 11/05/2006 16:09:47:
> At 10:12 AM 5/11/2006 +0100, Ben.Young at risk.sungard.com wrote:
> >A dynamic version of concepts (I guess a combo of multi-methods and
> >adaptation) would be great for Python, but it's hard to see how it
could
> >be done simply and efficiently.
>
> Go back and read the post where I explained how, then. ;)
>
> Seriously, it can be done as a pretty straightforward refactoring of
> Guido's existing overloaded function implementation. You just need to
be
> able to pass in objects other than classes to define a signature.
>
> But I suppose maybe it's one of those things that's only obvious and
> straightforward to me, so I'll have to see if I can carve out some time
> this weekend to implement a demo.
>
> The harder problem is having a way to define overloaded methods that's
at
> least as convenient as 'def __iter__(self):' -- but that's a syntax
issue.
>
> It seems to me, however, that having something like a 'defop' keyword
would
> do the trick, if you also had argument types. So if you were
implementing
> UserList or UserDict, you could have some code like this in the class
body:
>
> defop len(self):
> return len(self.data)
>
> defop iter(self):
> return iter(self.data)
>
> defop operator.getitem(self, key):
> return self.data[key]
>
Why not
class Foo(object):
@specialize(arg(0))
def core.len(self)
...
I think this is somewhat how PyPy specializes some of its methods (modulo
syntax)
I don't know how this would appear in the class dict though? self.len()?
Cheers,
Ben
More information about the Python-3000
mailing list