<div dir="ltr">Yes, (g x) is the second argument to f. Consider the type signature:<br><div><br></div><div>(<*>) :: Applicative f => f (a -> b) -> f a -> f b</div><div><br></div><div>In this case, the type of f is ((->) r). Specialized to that type:</div><div><br></div><div>(<*>) :: (r -> a -> b) -> (r -> a) -> (r -> b)</div><div>f <*> g = \x -> f x (g x)</div><div><br></div><div>Breaking down the pieces...</div><div>f :: r -> a -> b</div><div>g :: r -> a</div><div>x :: r<br></div><div>(g x) :: a</div><div>(f x (g x)) :: b</div><div><br></div><div>The example is made a bit confusing by tossing in an fmap. As far as the definition above is concerned, 'f' in the example is ((+) <$> (+3)) and that has to be resolved before looking at <*>.</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Aug 22, 2016 at 9:07 AM, Olumide <span dir="ltr"><<a href="mailto:50295@web.de" target="_blank">50295@web.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi List,<br>
<br>
I'm struggling to relate the definition of a function as a function<br>
<br>
instance Applicative ((->) r) where<br>
    pure x = (\_ -> x)<br>
    f <*> g = \x -> f x (g x)<br>
<br>
with the following expression<br>
<br>
ghci> :t (+) <$> (+3) <*> (*100)<br>
(+) <$> (+3) <*> (*100) :: (Num a) => a -> a<br>
ghci> (+) <$> (+3) <*> (*100) $ 5<br>
508<br>
<br>
>From chapter 11 of LYH <a href="http://goo.gl/7kl2TM" rel="noreferrer" target="_blank">http://goo.gl/7kl2TM</a> .<br>
<br>
I understand the explanation in the book: "we're making a function that will use + on the results of (+3) and (*100) and return that. To demonstrate on a real example, when we did (+) <$> (+3) <*> (*100) $ 5, the 5 first got applied to (+3) and (*100), resulting in 8 and 500. Then, + gets called with 8 and 500, resulting in 508."<br>
<br>
The problem is that I can't relate that explanation with the definition of a function as an applicative; especially f <*> g = \x -> f x (g x) . Is (g x) the second argument to f?<br>
<br>
Regards,<br>
<br>
- Olumide<br>
______________________________<wbr>_________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bi<wbr>n/mailman/listinfo/beginners</a><br>
</blockquote></div><br></div>