Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is `($ 4) (> 3)` equivalent to `4 > 3`?

Tags:

haskell

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.

like image 848
apc Avatar asked May 07 '12 05:05

apc


People also ask

What is the fraction 4 3 equivalent to?

Hence, the equivalent fractions of 4/3 are 8/6, 12/9, 16/12, etc.

How do you solve equivalent fractions?

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.

Which of the following is equivalent to 4 by 5?

Hence, 8/10, 12/15 and 16/20, 20/25 are equivalent fractions of 4/5.


1 Answers

($ 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).

like image 150
Lily Ballard Avatar answered Oct 05 '22 23:10

Lily Ballard