[Haskell-beginners] Usage of $
Martin Vlk
martin at vlkk.cz
Mon Jun 8 10:01:18 UTC 2015
Mike Meyer:
> s mp $ n - 1 parses as s mp (n - 1)
> s mp n - 1 parses as (s mp n) - 1
Hi, I think it is misleading to say that $ "parses" to something.
($) is an infix operator with type:
($) :: (a -> b) -> a -> b -- Defined in ‘GHC.Base’
infixr 0 $
So what it does is it takes a function on the left hand side and applies
it to the second argument on the right hand side. The trick is it has
the lowest possible precedence value (0) so everything on the right hand
side will be evaluated before applying the function on the left.
This is useful as a convenience if you want to avoid writing too many
parentheses.
Martin
More information about the Beginners
mailing list