I noticed as I was playing around with Haskell today that it is possible to do something like
($ 4) (> 3)
which yields True. What is going on here? It’d be great to have some intuition.
My guess? It looks like the ($ 4) is an incomplete function application, but where I’m confused is that $ is an infix operator, so shouldn’t it look like (4 $)? This doesn’t compile, so clearly not, which leads me to believe that I don’t really understand what’s going on. The (>3) term makes sense to me, because if you supply something like (\x -> x 4) (>3), you end up with the same result.
($ 4)is what’s called a section. It’s a way of partially applying an infix operator, but providing the right-hand side instead of the left. It’s exactly equivalent to(flip ($) 4).Similarly, (> 3) is a section.
can be rewritten as
which is the same as
which is the same as
And at this point, it should be clear that this boils down to
(4 > 3).