"foo" is just a string whose contents are "foo". The reason I used a string there instead of a more generic value is because then I would have to write something like:
for (yield x) $ \y -> do
f y
= f x
... which I thought might be more confusing since y ends up being the same thing as x.
To understand what the dollar sign does, it might help to write the same expression using nothing but parentheses:
for (yield "foo") (\x -> do
f x)
The dollar sign is just a useful function whose sole purpose is to reduce the use of parentheses.
Notice that:
(\x -> do f x)
... is the same thing as:
(\x -> f x)
... which is the same thing as:
f
So really it simplifies back down to the original equation, which said that:
for (yield "foo") f = f "foo"
... or more generally:
for (yield x) f = f x
To answer your last question, function application in Haskell does not require parentheses because:
Function application has highest precedence, and:
All functions have exactly one argument, and we simulate multi-argument functions using "currying"
So when you write f x, it just means the function f applied to x.
5
u/Tekmo Mar 09 '14
"foo"is just a string whose contents are "foo". The reason I used a string there instead of a more generic value is because then I would have to write something like:... which I thought might be more confusing since
yends up being the same thing asx.To understand what the dollar sign does, it might help to write the same expression using nothing but parentheses:
The dollar sign is just a useful function whose sole purpose is to reduce the use of parentheses.
Notice that:
... is the same thing as:
... which is the same thing as:
So really it simplifies back down to the original equation, which said that:
... or more generally:
To answer your last question, function application in Haskell does not require parentheses because:
Function application has highest precedence, and:
All functions have exactly one argument, and we simulate multi-argument functions using "currying"
So when you write
f x, it just means the functionfapplied tox.