[Haskell-beginners] ($) operator

Daniel Fischer daniel.is.fischer at web.de
Sat Jan 24 15:09:31 EST 2009


Am Samstag, 24. Januar 2009 20:37 schrieb John Hartnup:
> 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)

Indeed. ($) is the function application operator,

f $ x = f x

, so 
a $ b c d e f 
is equivalent to
a (b c d e f)
and
a $ b c $ d e f
to
a (b c (d e f)).

>
> But is that its only purpose? To placate the LISP haters by removing
> parentheses?

More or less. Although the idea was more to enhance readability than placating 
LISP haters :)
It's also handy to pass to some higher order functions, although offhand I 
can't think of any situation where you couldn't pass id instead of ($).

>
> (1 +) 2  does the same thing as (1 +) $ 2, and has the same type.
>
> Am I missing something?
>
> Thanks,
> John



More information about the Beginners mailing list