If the type for ($)
is (a -> b) -> a -> b
, then why are you allowed to curry it as ($2)
?
2 is not of type (a -> b)
.
See below example.
map ($2)[(+1),(+2)]
This is legit, awesome and intuitively makes sense. Please tell me how it is consistent with the type system rules?
Cheers
The behavior you are observing is due to how partial application works for infix operators. This is often called "section application" and you are applying 2
as the "right section" which would be the second argument. So you have:
($) :: (a -> b) -> a -> b
^
|
This is the type variable for the argument '2'
And you can confirm this via:
ghci
> :t ($2)
($2) :: Num a => (a -> b) -> b
You can likely find this info hidden somewhere in most decently complete tutorials or you can see the Haskell report section on sections.
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