<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 4 May 2013 19:33, Costello, Roger L. <span dir="ltr"><<a href="mailto:costello@mitre.org" target="_blank">costello@mitre.org</a>></span> wrote:<br><br>
<snip><br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div>
<br>
But then I saw this in an article:<br>
<br>
($ 3) odd<br>
<br>
What does ($ 3) mean? I thought the first argument to ($) is a function?<br>
<br>
I checked the type of ($ 3) and it is:<br>
<br>
($ 3) :: Num a => (a -> b) -> b<br>
<br>
I don't understand that. How did that happen? Why can I take a second argument and wrap it in parentheses with ($) and then that second argument pops out and becomes the argument to a function?<br></div></blockquote>
<div><br></div><div>These are called operator sections. Take a look at <a href="http://www.haskell.org/haskellwiki/Section_of_an_infix_operator">http://www.haskell.org/haskellwiki/Section_of_an_infix_operator</a><br></div>
<div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div>
<br>
I decided to see if other functions behaved similarly. Here is the type signature for the "map" function:<br>
<br>
map :: (a -> b) -> [a] -> [b]<br>
<br>
That looks very similar to the type signature for ($). So, I reasoned, I should be able to do the same kind of thing:<br>
<br>
let list=[1,2,3]<br>
(map list) odd<br>
<br>
But that fails. Why? Why does that fail whereas a very similar looking form succeeds when ($) is used?<br clear="all"></div></blockquote><div><br></div><div>Because (map list) is an ordinary function application since operator sections apply only to infix operators. On the other hand, had you written (`map` list), it would have worked as you expected. <br>
</div></div><br>λ. let list = [1, 2, 3]<br>λ. (`map` list) odd<br>[True,False,True]<br><br>-- <br>Denis Kasak
</div></div>