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.
Hence, the equivalent fractions of 4/3 are 8/6, 12/9, 16/12, etc.
For each fraction, we can find its equivalent fraction by multiplying both numerator and denominator with the same number. For example, we have to find the third equivalent fraction of ⅔; then we have to multiply 2/3 by 3/3. Hence, 2/3 × (3/3) = 6/9, is the fraction equivalent to 2/3.
Hence, 8/10, 12/15 and 16/20, 20/25 are equivalent fractions of 4/5.
($ 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.
($ 4) (> 3)
can be rewritten as
(flip ($) 4) (> 3)
which is the same as
flip ($) 4 (> 3)
which is the same as
(> 3) $ 4
And at this point, it should be clear that this boils down to (4 > 3)
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With