Why does filter odd.fst [(1,2), (2,3)]
give me a compile error? odd.fst
should take in a tuple of ints and output a boolean, so I am confused as to why the compiler is telling me it can't match types.
For the same reason that 2 * 3+4
is 10
, not 14
. Operator precedence does not care about spacing: 2 * 3+4
parses as (2 * 3) + 4
.
Similarly,
filter odd.fst [(1,2), (2,3)]
parses as
(filter odd) . (fst [(1,2), (2,3)])
no matter how you space it. This is because function application has higher precedence than any infix operator.
You want
filter (odd . fst) [(1,2), (2,3)]
instead.
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