Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org
You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Beginners digest..." Today's Topics: 1. Re: Functions as Applicatives (Olumide) 2. Re: Functions as Applicatives (Tony Morris) 3. Re: Functions as Applicatives (Imants Cekusins) ---------------------------------------------------------------------- Message: 1 Date: Tue, 23 Aug 2016 12:28:09 +0100 From: Olumide <50...@web.de> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: Re: [Haskell-beginners] Functions as Applicatives Message-ID: <4aa266c7-5e26-90a8-9422-21c2dee55...@web.de> Content-Type: text/plain; charset=utf-8; format=flowed I must be missing something. I thought f accepts just one argument. - Olumide On 23/08/2016 00:54, Theodore Lief Gannon wrote: > Yes, (g x) is the second argument to f. Consider the type signature: > > (<*>) :: Applicative f => f (a -> b) -> f a -> f b > > In 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 -> b > g :: r -> a > x :: r > (g x) :: a > (f x (g x)) :: b > > 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 <*>. > > > On Mon, Aug 22, 2016 at 9:07 AM, Olumide <50...@web.de > <mailto:50...@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 <mailto:Beginners@haskell.org> > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > <http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners> > > > > > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > ------------------------------ Message: 2 Date: Tue, 23 Aug 2016 21:39:43 +1000 From: Tony Morris <tonymor...@gmail.com> To: beginners@haskell.org Subject: Re: [Haskell-beginners] Functions as Applicatives Message-ID: <63fa5813-f5ee-e9d7-f0f6-28899ec19...@gmail.com> Content-Type: text/plain; charset="utf-8" All functions in Haskell always take one argument. On 23/08/16 21:28, Olumide wrote: > I must be missing something. I thought f accepts just one argument. > > - Olumide > > On 23/08/2016 00:54, Theodore Lief Gannon wrote: >> Yes, (g x) is the second argument to f. Consider the type signature: >> >> (<*>) :: Applicative f => f (a -> b) -> f a -> f b >> >> In 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 -> b >> g :: r -> a >> x :: r >> (g x) :: a >> (f x (g x)) :: b >> >> 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 <*>. >> >> >> On Mon, Aug 22, 2016 at 9:07 AM, Olumide <50...@web.de >> <mailto:50...@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 <mailto:Beginners@haskell.org> >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> <http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners> >> >> >> >> >> _______________________________________________ >> 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 -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 473 bytes Desc: OpenPGP digital signature URL: <http://mail.haskell.org/pipermail/beginners/attachments/20160823/b8fa9ec5/attachment-0001.sig> ------------------------------ Message: 3 Date: Tue, 23 Aug 2016 14:00:01 +0200 From: Imants Cekusins <ima...@gmail.com> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: Re: [Haskell-beginners] Functions as Applicatives Message-ID: <CAP1qinYd6QCbmO0DONrKV8+TXuTnHQCDJd=ewdd4ynkvh65...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" > I thought f accepts just one argument. if f is (+) then f::a -> a -> a -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20160823/7f03ffa3/attachment-0001.html> ------------------------------ Subject: Digest Footer _______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners ------------------------------ End of Beginners Digest, Vol 98, Issue 16 *****************************************