question regarding the $ apply operator

Hi I have a naive question regarding the basic use of the $ operator, and I am confused why certain times it doesn't seem to work. e.g. The following works: applySkip i f ls = (take i) ls ++ f (drop i ls) But the following doesn't: applySkip i f ls = (take i) ls ++ f $ drop i ls which gives me an error: The first argument of ($) takes one argument, but its type `[a0]' has none In the expression: (take i) ls ++ f $ drop i ls In an equation for `applySkip': applySkip i f ls = (take i) ls ++ f $ drop i ls FYI, I am using GHC 7.0.3 for this. Thanks in advance for comments. Ting

applySkip i f ls = (take i) ls ++ f (drop i ls)
But the following doesn't:
applySkip i f ls = (take i) ls ++ f $ drop i ls
The issue is with operator precedence. The above is equivalent to:
applySkip i f ls = ((take i) ls ++ f) (drop i ls)
(++) binds more strongly than ($).

On Tue, Jul 19, 2011 at 02:16, Ting Lei
I have a naive question regarding the basic use of the $ operator, and I am confused why certain times it doesn't seem to work. e.g. The following works:
applySkip i f ls = (take i) ls ++ f (drop i ls)
But the following doesn't:
applySkip i f ls = (take i) ls ++ f $ drop i ls
($) has lower precedence than almost every other operator, so your "doesn't work" translates to
applySkip i f ls = ((take i) ls ++ f) $ (drop i ls)
-- brandon s allbery allbery.b@gmail.com wandering unix systems administrator (available) (412) 475-9364 vm/sms

Thanks, Brandon,
That's a very clear explanation. I remembered that it's low, but forgot that it's this low.
Maybe it's because of my mis-understanding that in C, infix operators have lower precedence.
Just curious, the following is not allowed in Haskell either for the same reason.
applySkip i f ls = (take i) ls ++ $ f $ drop i ls
I read somewhere that people a couple of hundreds of years ago can manage to express things using ($)-like notation without any parenthesis at all.
Is it possible to define an operator to achieve this which works with infix operators? If so, then ($) and parentheses are then really equivalent.
Best,
Ting
Date: Tue, 19 Jul 2011 02:22:47 -0400
Subject: Re: [Haskell-cafe] question regarding the $ apply operator
From: allbery.b@gmail.com
To: tinlyx@hotmail.com
CC: haskell-cafe@haskell.org
On Tue, Jul 19, 2011 at 02:16, Ting Lei
applySkip i f ls = ((take i) ls ++ f) $ (drop i ls) -- brandon s allbery allbery.b@gmail.com
wandering unix systems administrator (available) (412) 475-9364 vm/sms

On 19 July 2011 06:52, Ting Lei
I read somewhere that people a couple of hundreds of years ago can manage to express things using ($)-like notation without any parenthesis at all.
The only thing that I can think of that matches this is Reverse Polish Notation, and according to Wikipedia was about 90 years ago, not hundreds ;-) -- Ivan Lazar Miljenovic Ivan.Miljenovic@gmail.com IvanMiljenovic.wordpress.com

On Tue, 2011-07-19 at 07:11 +0000, Ivan Lazar Miljenovic wrote:
On 19 July 2011 06:52, Ting Lei
wrote: I read somewhere that people a couple of hundreds of years ago can manage to express things using ($)-like notation without any parenthesis at all.
The only thing that I can think of that matches this is Reverse Polish Notation, and according to Wikipedia was about 90 years ago, not hundreds ;-)
I may be wrong but weren't the RPN calculator slightly later then 90 years ago? In any case according to wikipedia RPN was proposed in 1954 so less then 60 years ago. (PN on the other hand was found around 90 years ago). Regards

On 19 July 2011 09:51, Maciej Marcin Piechotka
On Tue, 2011-07-19 at 07:11 +0000, Ivan Lazar Miljenovic wrote:
The only thing that I can think of that matches this is Reverse Polish Notation, and according to Wikipedia was about 90 years ago, not hundreds ;-)
I may be wrong but weren't the RPN calculator slightly later then 90 years ago? In any case according to wikipedia RPN was proposed in 1954 so less then 60 years ago. (PN on the other hand was found around 90 years ago).
You're right; I mis-read the wikipedia article whilst skimming it. -- Ivan Lazar Miljenovic Ivan.Miljenovic@gmail.com IvanMiljenovic.wordpress.com

Polish notation was indeed published in 1920. However, it relies on knowing the arity of each symbol. Put another way, it relies on symbols *having* definite arities. Thus if f has 2 arguments, it has 2, not 1. This does not suit languages like Haskell at all well. Worse, as usually presented, it doesn't handle higher order functions. Suppose we wrote flip - 3 4 Polish notation doesn't really have the notion of a subexpression yielding an operator. One could patch Polish notation by assigning each symbol a rank as well as an arity, but I'll leave the details out because (a) I'm not sure it works very well, and (b) I've never found Polish notation (forward or reverse) to be even close to readable. Apparently the first known use of the parenthesis symbols () in England is in 1494. Presumably mainland Europe was using them before, but not all that long before. This was for asides in normal text. According to http://jeff560.tripod.com/mathsym.html the first uses of various kinds of brackets in mathematics go back to the mid 16th century. We haven't really had operator precedence for more than a few hundred years, or operators, come to that. So yes, it _is_ true "that people a couple of hundreds of years ago [could] manage to express [mathematics] without any parenthes[e]s at all". What clever notation did they use? Words. Lots of words. Sometimes heavily abbreviated words. Parentheses are *better*.

I know the Reverse Polish is not a couple of hundred years old.
I have an impression of reading something about people writing natural
deduction systems using only dots in place of parenthesis. And it is
said that it was "natural" in those pre-historic times.
That's also why I had this (mis-)conception that ($) can be used to achieve
something similar. It would be marginally interesting, since it saves us
one character in the mental stack. I still remember looking at the parentheses
in a lisp program.
Anyways, thanks for the clarifications.
On 19 July 2011 09:51, Maciej Marcin Piechotka
On Tue, 2011-07-19 at 07:11 +0000, Ivan Lazar Miljenovic wrote:
The only thing that I can think of that matches this is Reverse Polish Notation, and according to Wikipedia was about 90 years ago, not hundreds ;-)
I may be wrong but weren't the RPN calculator slightly later then 90 years ago? In any case according to wikipedia RPN was proposed in 1954 so less then 60 years ago. (PN on the other hand was found around 90 years ago).
You're right; I mis-read the wikipedia article whilst skimming it. -- Ivan Lazar Miljenovic Ivan.Miljenovic@gmail.com IvanMiljenovic.wordpress.com

On Sat, 2011-07-23 at 06:37 -0700, Ting Lei wrote:
I know the Reverse Polish is not a couple of hundred years old. I have an impression of reading something about people writing natural deduction systems using only dots in place of parenthesis. And it is said that it was "natural" in those pre-historic times.
That's also why I had this (mis-)conception that ($) can be used to achieve something similar. It would be marginally interesting, since it saves us one character in the mental stack. I still remember looking at the parentheses in a lisp program.
Anyways, thanks for the clarifications.
Hmm. Maybe highlighting the parenthesis would help in more complicated expressions. I.e. the matching parenthesis are coloured in the same colour. For example (((()())())) rgbyyccbppgr r - red g - green b - blue c - black p - pink Regards

On Mon, Jul 18, 2011 at 11:52:15PM -0700, Ting Lei wrote:
Thanks, Brandon,
That's a very clear explanation. I remembered that it's low, but forgot that it's this low. Maybe it's because of my mis-understanding that in C, infix operators have lower precedence.
Just curious, the following is not allowed in Haskell either for the same reason.
applySkip i f ls = (take i) ls ++ $ f $ drop i ls
I read somewhere that people a couple of hundreds of years ago can manage to express things using ($)-like notation without any parenthesis at all. Is it possible to define an operator to achieve this which works with infix operators? If so, then ($) and parentheses are then really equivalent.
($) and parentheses are quite different. Anyone who tells you they are equivalent, although probably well-meaning, should be ignored. Here is everything you need to know about ($): infixr 0 $ f $ x = f x Although working out all the implications of this definition may take a bit of practice. -Brent
participants (7)
-
Arlen Cuss
-
Brandon Allbery
-
Brent Yorgey
-
Ivan Lazar Miljenovic
-
Maciej Marcin Piechotka
-
Richard O'Keefe
-
Ting Lei