Yes, (g x) is the second argument to f. Consider the type signature:(<*>) :: Applicative f => f (a -> b) -> f a -> f bIn this case, the type of f is ((->) r). Specialized to that type:(<*>) :: (r -> a -> b) -> (r -> a) -> (r -> b)f <*> g = \x -> f x (g x)Breaking down the pieces...f :: r -> a -> bg :: r -> ax :: r(g x) :: a(f x (g x)) :: bThe 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 <*>._______________________________________________On Mon, Aug 22, 2016 at 9:07 AM, Olumide <50295@web.de> wrote:Hi List,
I'm struggling to relate the definition of a function as a function
instance Applicative ((->) r) where
pure x = (\_ -> x)
f <*> g = \x -> f x (g x)
with the following expression
ghci> :t (+) <$> (+3) <*> (*100)
(+) <$> (+3) <*> (*100) :: (Num a) => a -> a
ghci> (+) <$> (+3) <*> (*100) $ 5
508
>From chapter 11 of LYH http://goo.gl/7kl2TM .
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."
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?
Regards,
- Olumide
_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners