Functional Programming and python

Jussi Piitulainen jpiitula at ling.helsinki.fi
Tue Sep 24 10:51:19 EDT 2013


rusi writes:
> 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.

Ok.

> 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.

Strictly speaking and in principle, yes. I'm not sure how important
this is in practice: the positional parameter list should be short
anyway, Haskell does have the special mechanism for the second, and
there is always the fully general mechanism (lambda) in both languages
(and in another language I use that has neither built-in currying nor
keyword parameters :).

I agree that the ability to identify arguments by name gives a useful
amount of quite practical power, and I see that functools.partial uses
it nicely. So, no real disagreement on this from me.

Would the type system get in the way of providing some analogous
function in Haskell? I don't know.

> 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:

[snip]

Thanks. I don't think I have anything useful to add, though.



More information about the Python-list mailing list