[Haskell-cafe] About ($)

robert dockins robdockins at fastmail.fm
Thu Jun 2 15:08:13 EDT 2005

> Hello there,
> name's Frank-Andre Riess. Nice to meet you m(_ _)m


> So, well, my first question on this list is admittedly somewhat simple, but I
> managed to delay it long enough and now I think I should ask about it: Does
> ($) have any relevance at all except for being a somewhat handier version of
> parentheses?

That's mostly how it is used (although some will say that it is a 
terrible idea), but one can also do some pretty neat tricks with it as a 
higher-order function.  Eg,

zipWith ($)

Is a function which takes a list of functions and a list of arguments 
and applies the functions pairwise with the arguments.  In addition, 
because of the way the zip* functions work, you can create an infinite 
cycle of functions to apply to some arguments as in:

zipWith ($) (cycle [sin,cos]) [1..5]

which is equivalent to:

[sin 1,cos 2,sin 3,cos 4,sin 5]

I'm sure there are other more esoteric things, but this is about as 
complex as I try to go to avoid severe headaches :)

Robert Dockins

More information about the Haskell-Cafe mailing list