Reputation: 15906
I have the following function definitions (which are equivalent):
reverseWords :: String -> String
reverseWords wds = unwords . map reverse . words $ wds
and
reverseWords :: String -> String
reverseWords = unwords . map reverse . words
I understand that they are equivalent as they yield the same result but I'm a bit confused about the second form.
If I call a function like:
reverseWords abc
How does haskell decide where to place this 'abc' parameter?
Upvotes: 1
Views: 107
Reputation: 59701
Haskell does not need to decide where to place abc
. When you call reverseWords
in your second example it will simply return unwords . map reverse . words
.
And then abc gets applied to that with which you will end up with the same result as in your first example.
This is also called Point-free style as you can read more about it here: https://wiki.haskell.org/Point-free
Upvotes: 1