I'm new to Haskell and looking at a simple example of using function application with $
.
It seems straightforward - it takes a function and applies it to a value.
So this makes sense:
> (+3) $ 2
5
This also makes sense:
> ($) (+3) 2
5
This makes sense because the first argument is the function, and the second argument is the value.
Now considering using $
to create a partial function.
Looking at types, this makes sense - it just needs a Num
type value for b
:
> :t ($) (+3)
($) (+3) :: Num b => b -> b
But here's where I get lost - what is happening here?:
> :t ($) (2)
($) (2) :: Num (a -> b) => a -> b
I would have expected the first argument would need to be a function, not a simple Num value.
So here's my questions:
- What's happening here?
- What does the constraint
Num (a -> b)
syntax mean? - What's an example of using
($)
in this way, that starts with something like($) (2)
?
Thanks!