Functional programming in Python
Dean Herington
heringto@cs.unc.edu
Tue, 22 May 2001 13:16:55 -0400
brk@jenkon.com wrote:
> There's another piece to this question that we're overlooking, I
> think. It's not just a difference (or lack thereof) in precedence, it's the
> fact that parentheses indicate application in Python and many other
> languages, and a function name without parentheses after it is a reference
> to the function, not an application of it. This has nothing to do with
> currying that I can see - you can have curried functions in Python, and they
> still look the same. The main advantage I see for the Haskell style is
> (sometimes) fewer keypresses for parentheses, but I still find it surprising
> at times. Unfortunately in many cases you need to apply nearly as many
> parens for a Haskell expression as you would for a Python one, but they're
> in different places. It's not:
>
> foo( bar( baz( x ) ) )
> it's:
> (foo ( bar (baz x) ) )
>
> I'm not sure why folks thought this was an improvement. I suppose it
> bears more resemblance to lambda calculus?
In Haskell, one doesn't need to distinguish "a reference to the function" from
"an application of it". As a result, parentheses need to serve only a single
function, that of grouping. Parentheses surround an entire function
application, just as they surround an entire operation application:
foo (fum 1 2) (3 + 4)
I find this very consistent, simple, and elegant.
Dean