Difference between revisions of "$"
From HaskellWiki
(A new page for the $ operator explaining its usefulness) 
(No difference)

Revision as of 02:36, 16 April 2012
$ is an infix operator often seen in Haskell code. It applies the function on its left to the value on its right. At first glance this operator appears redundant, since ordinary application (f x)
means the same as (f $ x)
. However, $
has the lowest, rightassociative binding precedence (infixr 0), so it sometimes allows parentheses to be omitted; for example:
f $ g $ h x = f (g (h x))
If $
were omitted, the parse would be different:
f g h x = ((f g) h) x
It is also useful in higherorder situations, such as map ($ 0) xs
, or zipWith ($) fs xs
.
Definition
$ comes from the Prelude, where it is defined as:
infixr 0 $ ($) :: (a > b) > a > b f $ x = f x