Why not use juxtaposition to indicate function application

R

Ray Song

I confess i've indulged in Haskell and found
f a
more readable than
f(a)

And why aren't functions curried (partially applied function is another function which takes the rest arguments) by default?


Thanks in advance for any suggestions.
 
B

bruno.desthuilliers

I confess i've indulged in Haskell and found
    f a
more readable than
    f(a)

Hmmm... What about:

f a b

versus

f(a(b))

or was it supposed to be read as

f(a)(b)


or as

f(a, b)

?-)


And why aren't functions curried (partially applied function is another function which takes the rest arguments) by default?


If you're asking "why isn't Python like Haskell", the obvious answer
is, well, "because Python is not Haskell" ;)

Remember that Pythons is first and foremost an object-oriented
language, where most of the support for functional idioms comes from
the underlying object model. functions are central to fp, objects are
central to OOP, so better to use objects than functions (hint: there's
a builtin "partial" type).
 
C

Colin J. Williams

I confess i've indulged in Haskell and found
f a
more readable than
f(a)

And why aren't functions curried (partially applied function is another function which takes the rest arguments) by default?


Thanks in advance for any suggestions.
+1

Colin W.
 
P

Prasad, Ramit

I confess i've indulged in Haskell and found
That would be
f (a b) # Haskell
f(a(b)) # Python

I have not used Haskell so far, but in this case I think I prefer the
'Explicit is better than implicit.'

I would probably always forget if it should be

f a b

or

f( a b )

Not to mention the first line look like text rather than a function call
because my mind tends to filter out whitespaces likethat when reading.
I blame variable width fonts (and the mind beinga strange thing).


Ramit


Ramit Prasad |JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423

--
This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.
 
S

Steven D'Aprano

You wouldn't, because Haskel's way is more regular and makes a lot of
sense: parentheses are for grouping and that's it.

If f is a function which normally takes (for the sake of the argument)
one argument, then f would call the function with no arguments (which may
return a curried function, or may apply default arguments, or perhaps
raise an exception). So how would you refer to the function itself
without calling it?
 
I

Ian Kelly

If f is a function which normally takes (for the sake of the argument)
one argument, then f would call the function with no arguments (which may
return a curried function, or may apply default arguments, or perhaps
raise an exception). So how would you refer to the function itself
without calling it?

A partial application of f with no arguments is still just f.
 
S

Serhiy Storchaka

16.03.12 18:45, Steven D'Aprano напиÑав(ла):
If f is a function which normally takes (for the sake of the argument)
one argument, then f would call the function with no arguments (which may
return a curried function, or may apply default arguments, or perhaps
raise an exception). So how would you refer to the function itself
without calling it?

lambda:f
 
S

Serhiy Storchaka

16.03.12 23:02, Chris Rebert напиÑав(ла):
Doesn't help; wouldn't the lambda be implicitly called?

No, the lambda is only for declaration. I prefer to use braces for
lambda syntax, it will be fine with 'if' and 'while' functions.

But all this for some other, fictitious, language, not for Python.
 
T

Terry Reedy

Hmmm... What about:

f a b

versus

f(a(b))

or was it supposed to be read as

f(a)(b)


or as

f(a, b)

?-)

One also has to consider Python calls with *args, **kwds, and arg=obj.
These are all compile-time SyntaxErrors unless inside parens that follow
a expression.

Also, function calls, especially in a functional language without
side-effects, do not usually occur in isolation.
'f(a) + 3' would have to be written as '(f a) + 3', so saving of parens
anyway.

Also, is 'f a - 2' f(a -2) or f(a, -2)? A new precedence rule is needed
to disambiguage.
 
R

rusi

I confess i've indulged in Haskell and found
    f a
more readable than
    f(a)

And why aren't functions curried (partially applied function is another function which takes the rest arguments) by default?

Thanks in advance for any suggestions.

In Haskell
a b c d is short for (((a b) c) d)

This works nicely when the latter is commonly required, as for example
happens in a language where what one may call 'the currying
convention' is the default.
It fails when one wants the opposite convention -- a (b (c (d))) --
which may be called the 'function-composition convention.'

The fact that the default convention in haskell is not always a good
idea is seen in the existence of a special application operator $ with
low precedence which allows
a (b (c (d))) to be written as a $ b $ c $ d

It is another matter: as someone pointed out that () is overloaded in
python to denote:
- function application
- tupling
- grouping

Comes from the hegemony of ASCII.
A from-first-principles unicode language would use more of these:
http://xahlee.org/comp/unicode_matching_brackets.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top