[Python-Dev] PEP 443 - Single-dispatch generic functions (original) (raw)
Armin Rigo arigo at tunes.org
Thu May 23 09:33:33 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 ]
Hi,
On Thu, May 23, 2013 at 12:33 AM, Ćukasz Langa <lukasz at langa.pl> wrote:
Alternative approaches ======================
You could also mention "pairtype", used in PyPy: https://bitbucket.org/pypy/pypy/raw/default/rpython/tool/pairtype.py (very short code). It's originally about adding double-dispatch, but the usage that grew out of it is for generic single-dispatch functions that are bound to some common "state" object as follows (Python 2 syntax):
class MyRepr(object): ...state of my repr...
class extend(pairtype(MyRepr, int)): def show((myrepr, x), y): print "hi, I'm the integer %d, arg is %s" % (x, y)
class extend(pairtype(MyRepr, list)): def show((myrepr, x), y): print "hi, I'm a list" ...use myrepr to control the state...
pair(MyRepr(), [2,3,4]).show(42)
- Armin
- 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 ]