Reputation: 1229
I'm trying to learn how the ($) operator works. I run
(+5) ($) 7
I get
* Non type-variable argument in the constraint: Num (a -> b)
(Use FlexibleContexts to permit this)
* When checking the inferred type
it :: forall a b.
(Num (a -> b), Num ((a -> b) -> a -> b)) =>
a -> b
Could anyone help me understand why I get this error ?
Upvotes: 1
Views: 118
Reputation: 356
Much like (+) is the prefix form of +.
($), called function application, is the prefix form of $.
> (+) 1 2 == 1 + 2
True
So if you want to apply (+5) to 7 then ($) would do that in this syntax
> ($) (+5) 7
12
which is equivalent to
> (+5) $ 7
12
Note that $ is most often used to simplify syntax.
Upvotes: 2
Reputation: 1229
I should have done
(+5) $ 7
I still not sure I understand the difference.
Upvotes: 0