[Python-ideas] @partials = decorators

Steven D'Aprano steve at pearwood.info
Sat Feb 8 23:06:57 CET 2014


On Sat, Feb 08, 2014 at 11:55:56AM -0600, Ron Adam wrote:

> What if these *calls* were equivalent...
> 
>      S(x, y, z)  ==  S(x)(y)(z)

If you want Haskell, you know where to find it :-)

http://www.haskell.org/haskellwiki/Currying

But seriously, I think that is a perfectly fine design decision for a 
functional language like Haskell, but it's one which would be awful for 
a multi-paradigm language like Python which is aimed at a more general 
programming audience. That means you would never again get an explicit 
TypeError from leaving out a mandatory argument[1], since *no* arguments 
are mandatory, you'd just get a mysterious partial application object.

When a beginner, or Java programmer, writes:

result = getattr(obj)  # Oops, forgot the attribute name.
# much later on...
print(result + 1)

I wouldn't like to be the one to explain the eventual error they get. Or 
worse, they do this:

method = getattr(obj)  # Oops, forgot the method name.
result = method(some_string)

which is likely to mysteriously succeed for some strings, and fail for 
others.

I think that for Python, having to explicitly perform partial 
application is a good thing.




[1] With the possible exception of not providing any arguments at all.

-- 
Steven


More information about the Python-ideas mailing list