I'm learning some haskell since this weekend, I found this language interesting, but also some syntaxs make me confused.
Like, zip
is a function that take 2 list as parameters and then return a list of pairs.
if I invoke zip [1,2,3] [3,2,1]
in ghci
I got [(1,3),(2,2),(3,1)]
. But if I say (zip [1,2,3]) [3,2,1]
it returns the same result.
When I looked into the definition of the zip function using :i zip
, I got zip :: [a] -> [b] -> [(a, b)] -- Defined in ‘GHC.List’
, from this it seems that zip
is a function apply the first parmeter, return a function and then apply to the second parameter.
Another example is elem
, elem 1 [1,2,3]
, (elem 1) [1,2,3]
and (1 `elem`) [1,2,3]
return the same result.
So my question is if a function receive multiple parameters, how this function evaluate, process each parameter in order or just process all parameters in one time.