[Haskell-cafe] question regarding the $ apply operator

Ting Lei tinlyx at hotmail.com
Tue Jul 19 08:52:15 CEST 2011


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 at gmail.com
To: tinlyx at hotmail.com
CC: haskell-cafe at haskell.org

On Tue, Jul 19, 2011 at 02:16, Ting Lei <tinlyx at hotmail.com> wrote:





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 at gmail.com

wandering unix systems administrator (available)     (412) 475-9364 vm/sms


 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20110718/8bcac409/attachment-0001.htm>


More information about the Haskell-Cafe mailing list