[Python-Dev] Right curry considered harmful (original) (raw)

Peter Harris scav at blueyonder.co.uk
Tue Aug 31 22:24:29 CEST 2004


Alex Nanouu wrote:

though this might be a bit late, I would like to suggest something a bit functionally different: ---cut--- class LCurry(object): ''' this is the left curry class. ''' def new(cls, func, *args, **kw): obj = object.new(cls) if isinstance(func, LCurry) or isinstance(func, RCurry): obj.curryfunc = func.curryfunc obj.curryargs = (func.curryargs[0] + args, func.curryargs[1]) obj.currykw = kw = kw.copy() kw.update(func.currykw) else: obj.curryfunc = func obj.curryargs = (args, ()) obj.currykw = kw.copy() return obj def call(self, *args, **kw): self.curryfunc(*self.curryargs[0] + args + self.curryargs[1], **dict(self.currykw.items() + kw.items()))

--uncut-- this mainly has one thing different from the reference implementation in the pep: 1) it is recursive that is we can curry/partial something more than one and yet avoid the extra function call per curry level... IMO this is a worthwhile optimisation....

I think we'll see if partial() is a useful enough feature to be worth optimising once it actually makes it into a build and gets used.

Mostly I think nesting many layers of partial(), or optimising the implementation with that in mind will not be a win for clarity, therefore a net loss however fast you can make it.

By the way, I think 'right curry' is just a broken idea from the point of view of code readability. (I know the n'th argument is '2', but 'n' will depend on how many arguments are passed at run time!) The PEP doesn't propose to implement such a monster, or call partial() a curry at all, let alone a 'left' one.

Peter Harris



More information about the Python-Dev mailing list