The type signature for $
is as follows:
($) :: (a -> b) -> a -> b
Thus if plus1 n = n + 1
, then we have that
> ($) plus1 1
2
But then why is it that
> ($ 1) plus1
2
as well? The form ($ 1) plus1
seems to violate the type signature for $
.
If you try
(($) 1) plus1
you will get the type error you expect.
The special syntax ($ 1)
is called a section, and stands for \x -> x $ 1
, which differs from the plain application ($) 1
. This syntax can be used with all infix operators (*) e.g. (+ 1)
or (* 4)
.
(*) Except -
, since (- 10)
is the negative constant -10
.
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