[Haskell-beginners] ($) operator
Brent Yorgey
byorgey at seas.upenn.edu
Sat Jan 24 17:52:37 EST 2009
On Sat, Jan 24, 2009 at 07:37:29PM +0000, John Hartnup wrote:
> Hi.
>
> I'm working through Real World Haskell, and although it's going well
> (I just finished the exercise to write a glob matcher without using a
> regex library, and I'm pleased as punch), I keep seeing the ($)
> operator, and I'm not sure I understand its use. If the book explains
> it, I've been unable to find it.
>
> Empirically, it seems like:
> a $ b c d e f
> .. is equivalent to ..
> a (b c d e f)
>
> But is that it's only purpose? To placate the LISP haters by removing
> parentheses?
>
> (1 +) 2 does the same thing as (1 +) $ 2, and has the same type.
>
> Am I missing something?
More generally, in a language with first-class and higher-order
functions like Haskell, it's simply useful to have a function which
performs function application. For example, one place that ($) comes
in handy is when applying each function in a list of functions to a
single input value. Using ($) you can just write something like
map ($5) [(+1), (^2), abs]
which evaluates to [6,25,5].
-Brent
More information about the Beginners
mailing list