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 (Imants Cekusins) 2. Re: Functions as Applicatives (Imants Cekusins) 3. Re: Functions as Applicatives (Rein Henrichs) 4. Re: Functions as Applicatives (Olumide) 5. Re: Functions as Applicatives (Theodore Lief Gannon) 6. Re: Functions as Applicatives (Rein Henrichs) ---------------------------------------------------------------------- Message: 1 Date: Mon, 22 Aug 2016 19:42:02 +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: <CAP1qinYicmcFsV3zN+=wMMMhT-ocfPO8RN_3xe=_t6pkdog...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" fgh::Num a => a -> a fgh = fg <*> h {- fgh a = fg a (a * 100) fgh = \a -> fg a (a * 100) -} , that is -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20160822/2325b608/attachment-0001.html> ------------------------------ Message: 2 Date: Mon, 22 Aug 2016 20:13:30 +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: <CAP1qinaKi_2TS=8exygukcmxlurqknmmiyr99ix6pvojjdn...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" .. actually, I got fg wrong. Caught it by changing g to (/ ): f::Fractional f => f -> f -> f f = (+) g::Fractional g => g -> g g a = a / 2 h::Fractional h => h -> h h = (* 10) fg::Fractional a => a -> a -> a fg = f <$> g {- fg a b = (a / 2) + b fg a = \b -> (a / 2) + b -} fgh::Fractional a => a -> a fgh = fg <*> h {- fgh a = fg a (a * 10) fgh = \a -> fg a (a * 10) -} -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20160822/25e8cf31/attachment-0001.html> ------------------------------ Message: 3 Date: Mon, 22 Aug 2016 21:14:19 +0000 From: Rein Henrichs <rein.henri...@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: <cajp6g8wzqhv7vbbdfqvtfs23syxo3qiyre_kdot1y7ounkc...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" In f <*> g = \x -> f x (g x), g is the second argument to <*>. The result of f <*> g is a function that takes an argument (x) and gives f x (g x). So basically <*> combines the functions f and g in a particular way to give a new function. In fact, it is the only way to combine them that type checks (and doesn't use undefined or similar). On Mon, Aug 22, 2016 at 11:13 AM Imants Cekusins <ima...@gmail.com> wrote: > .. actually, I got fg wrong. Caught it by changing g to (/ ): > > > f::Fractional f => f -> f -> f > f = (+) > > g::Fractional g => g -> g > g a = a / 2 > > h::Fractional h => h -> h > h = (* 10) > > > fg::Fractional a => a -> a -> a > fg = f <$> g > {- fg a b = (a / 2) + b > fg a = \b -> (a / 2) + b > -} > > fgh::Fractional a => a -> a > fgh = fg <*> h > {- fgh a = fg a (a * 10) > fgh = \a -> fg a (a * 10) > -} > > > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20160822/d00370f2/attachment-0001.html> ------------------------------ Message: 4 Date: Tue, 23 Aug 2016 00:20:26 +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: <cfd73245-85c9-9be4-24a9-160643a63...@web.de> Content-Type: text/plain; charset=utf-8; format=flowed What exactly is f x (g x)? is it (f x)(g x)?? ... Looks like two numbers to me e.g. 42 43 ... This can only make sense if they are arguments to another binary function which I don't see. Or is there something I'm missing? - Olumide On 22/08/16 22:14, Rein Henrichs wrote: > In f <*> g = \x -> f x (g x), g is the second argument to <*>. The > result of f <*> g is a function that takes an argument (x) and gives f x > (g x). So basically <*> combines the functions f and g in a particular > way to give a new function. In fact, it is the only way to combine them > that type checks (and doesn't use undefined or similar). > > On Mon, Aug 22, 2016 at 11:13 AM Imants Cekusins <ima...@gmail.com > <mailto:ima...@gmail.com>> wrote: > > .. actually, I got fg wrong. Caught it by changing g to (/ ): > > > f::Fractional f => f -> f -> f > f = (+) > > g::Fractional g => g -> g > g a = a / 2 > > h::Fractional h => h -> h > h = (* 10) > > > fg::Fractional a => a -> a -> a > fg = f <$> g > {- fg a b = (a / 2) + b > fg a = \b -> (a / 2) + b > -} > > fgh::Fractional a => a -> a > fgh = fg <*> h > {- fgh a = fg a (a * 10) > fgh = \a -> fg a (a * 10) > -} > > > _______________________________________________ > Beginners mailing list > Beginners@haskell.org <mailto: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 > ------------------------------ Message: 5 Date: Mon, 22 Aug 2016 16:54:21 -0700 From: Theodore Lief Gannon <tan...@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: <cajopsucsmt23pghecj9gui_gjkjgxhkmt10erw60nnkp4_4...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" 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> 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 > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20160822/df638d7a/attachment-0001.html> ------------------------------ Message: 6 Date: Tue, 23 Aug 2016 00:01:47 +0000 From: Rein Henrichs <rein.henri...@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: <cajp6g8xft7cgbk4aqhegnmp7tvopqbf0hhextagmcz6cind...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" Here's an example that may help: > ((==) <*> reverse) "radar" True Using the definition for (<*>), we have f = (==) and g = reverse, and this becomes: (==) "radar" (reverse "radar") Or, once we make (==) infix, "radar" == reverse "radar" So we might say: isPalindome x = ((==) <*> reverse) x And we can *eta reduce* that to get isPalindrome = (==) <*> reverse On Mon, Aug 22, 2016 at 4:54 PM Theodore Lief Gannon <tan...@gmail.com> 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> 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 > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20160823/6dcaf0ec/attachment.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 15 *****************************************