If first parameter is taken by the function first as function application is left-associative, for example:
drop 2 [1,2,3,4]
result: [3,4]
is equivalent to
(drop 2) [1,2,3,4]
same result: [3,4]
Here my question is, if the type signature is right-associative, which means, things in right side evaluate first, in this case, it's gonna be as follows, as the first parameter is first taken by the function:
drop :: [1,2,3,4] -> (2 -> [3,4])
It shouldn't have been as follows, right?
drop :: Int -> ([a] -> [a])
drop :: 2 -> ([1,2,3,4] -> [3,4])
So, why does it take the second parameter first in type signature of the function instead of the first parameter?
In addition, if the second parameter is evaluated prior to first parameter, then why is the following usage invalid?
(drop [1,2,3,4]) 2
I think you misunderstand what right associative means. It indeed means that:
is equivalent to:
This thus means that
drop
is a function that takes a parameter of typeInt
, and then returns a function of type[a] -> [a]
.But function application itself is left-associative. Indeed:
is short for:
Here
drop 2
will thus return a function of type[a] -> [a]
that will drop the first two items of the list. We then apply[1,2,3,4]
to that function, and thus obtain[3,4]
.