I am trying to understand sections and think I have got it. Basically it is a way to apply partial application to binary operators. So I understand all the (2*)
, (+1)
, etc. examples just fine.
But in the O'Reilly Real World Haskell book, Sections 'section' :) it has this example:
(`elem` ['a'..'z']) 'f'
>True
I understand the need for the parentheses - ie the section syntax. But why do I need the backticks?
If I try, I get:
(elem ['a'..'z']) 'f'
<interactive>:220:19:
Couldn't match expected type `[[Char]]' with actual type `Char'
In the second argument of `elem', namely 'f'
In the expression: (elem ['a' .. 'z']) 'f'
In an equation for `it': it = (elem ['a' .. 'z']) 'f'
In Haskell, the backtick turns a name to an infix operator:
a `elem` b = elem a b
So
(`elem` b) a = (\x -> x `elem` b) a
= a `elem` b
= elem a b
While
(elem b) a = elem b a
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