Functional Programming and python

rusi rustompmody at gmail.com
Tue Sep 24 08:14:53 EDT 2013


On Tuesday, September 24, 2013 1:12:51 PM UTC+5:30, Jussi Piitulainen wrote:
> rusi writes:
> 
> > Without resorting to lambdas/new-functions:
> >  With functools.partial one can freeze any subset of a
> >  function(callable's) parameters.
> >
> 
> >  In Haskell one can only freeze the first parameter or at most with
> >  a right section the second
> 
> You have an f of type A -> B -> C -> D -> E in Haskell, you can freeze
> the first three parameters by calling it with three arguments. These
> are equivalent:
> 
> f a b c d
> (f a b c) d
> (f a b) c d
> (f a) b c d
> 
> So it's any initial sequence of arguments, not just the first.

Agreed. I missed that.

However as n increases there are n initial sequences (Haskell) whereas there are 2^n possible subsets (Python) (2^n - 1 if we remove the fully saturated case). So I would argue that Python syntax gives more flexibility in this direction than Haskell.  Add the further feature of **args and its even more

> 
> (I also think that the word "currying" used to refer to what Haskell
> does and it's an extension to use it to mean any partial evaluation.)

Hmm… Seems this is a contentious issue
http://en.wikipedia.org/wiki/Currying#Contrast_with_partial_function_application

which links to this LtU post that I find neat:

---------------
If I have a function f:(x,y)->z, I can't apply it to only one of its arguments. I can curry it, turning it into a function g:x->(y->z) ... and I can apply g to only one of the original arguments. But turning f into g and applying g to some x are technically different things.

I suspect the confusion arises because originally currying was a technique to model multiple-argument functions in a single-argument framework and was a meta-operation. In ML-like languages, the functions are typically already curried, so the only operation you see being done is partial application.
---------------
from http://lambda-the-ultimate.org/node/2266

-------------
Anyways thanks for that Ive added it to my 'lost-booty' list
http://blog.languager.org/2012/10/functional-programming-lost-booty.html#curry



More information about the Python-list mailing list