<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: The basics of applicative functors, put to practical work</title>
	<atom:link href="http://www.serpentine.com/blog/2008/02/06/the-basics-of-applicative-functors-put-to-practical-work/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.serpentine.com/blog/2008/02/06/the-basics-of-applicative-functors-put-to-practical-work/</link>
	<description>Bryan O&#039;Sullivan&#039;s blog</description>
	<lastBuildDate>Wed, 08 Feb 2012 06:41:38 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Gene Arthur</title>
		<link>http://www.serpentine.com/blog/2008/02/06/the-basics-of-applicative-functors-put-to-practical-work/comment-page-1/#comment-251653</link>
		<dc:creator>Gene Arthur</dc:creator>
		<pubDate>Mon, 14 Dec 2009 15:40:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.serpentine.com/blog/2008/02/06/the-basics-of-applicative-functors-put-to-practical-work/#comment-251653</guid>
		<description>(* 8)  that is supposed to be times 8  -- eight and came out a smiley on my monitor in my comment above.. oh well.</description>
		<content:encoded><![CDATA[<p>(* <img src='http://www.serpentine.com/wordpress/wp-includes/images/smilies/icon_cool.gif' alt='8)' class='wp-smiley' />  that is supposed to be times 8  &#8212; eight and came out a smiley on my monitor in my comment above.. oh well.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gene Arthur</title>
		<link>http://www.serpentine.com/blog/2008/02/06/the-basics-of-applicative-functors-put-to-practical-work/comment-page-1/#comment-251651</link>
		<dc:creator>Gene Arthur</dc:creator>
		<pubDate>Mon, 14 Dec 2009 15:37:34 +0000</pubDate>
		<guid isPermaLink="false">http://www.serpentine.com/blog/2008/02/06/the-basics-of-applicative-functors-put-to-practical-work/#comment-251651</guid>
		<description>Harkening back to the original premise of this entry, I would like to plug the versatility aspect of the applicatives on functors as opposed to using the monadic machinations.
The problem with using monads and bind comes in the type situation. The monads have to match if outside of bind for the next level monad down, as in this situation:


catMaybes $ [1..12] &gt;&gt;= ((\x -&gt; if x &gt;&gt; return) &gt;&gt;= (liftM (* 8) &gt;&gt;&gt; return)

[40,48,56,64,72,80,88,96]

Using applicative operators along with arrows you get the above with the catMaybe on the inside of the computational unit which is not possible as far as I can see with a single monad construction, without resorting to using the ($) outside of the application.  Here is the same thing using the () from Control.Applicative and a new operator that I built, () that just extends down another functor layer:
()
  :: forall a b (f1 :: * -&gt; *) (f :: * -&gt; *).
     (Functor f, Functor f1) =&gt;
     (a -&gt; b) -&gt; f1 (f a) -&gt; f1 (f b)


*Big3&gt; ((\x -&gt; if x &lt; 5 then Nothing else Just x) ) &gt;&gt;&gt; ((* 8) ) &gt;&gt;&gt; catMaybes $ [1..12]  
                 
[40,48,56,64,72,80,88,96]

I will have to delve into Parsec module someday, but been having WAY to much fun, mucking about with other things.

Cheers,
gene</description>
		<content:encoded><![CDATA[<p>Harkening back to the original premise of this entry, I would like to plug the versatility aspect of the applicatives on functors as opposed to using the monadic machinations.<br />
The problem with using monads and bind comes in the type situation. The monads have to match if outside of bind for the next level monad down, as in this situation:</p>
<p>catMaybes $ [1..12] &gt;&gt;= ((\x -&gt; if x &gt;&gt; return) &gt;&gt;= (liftM (* <img src='http://www.serpentine.com/wordpress/wp-includes/images/smilies/icon_cool.gif' alt='8)' class='wp-smiley' /> &gt;&gt;&gt; return)</p>
<p>[40,48,56,64,72,80,88,96]</p>
<p>Using applicative operators along with arrows you get the above with the catMaybe on the inside of the computational unit which is not possible as far as I can see with a single monad construction, without resorting to using the ($) outside of the application.  Here is the same thing using the () from Control.Applicative and a new operator that I built, () that just extends down another functor layer:<br />
()<br />
  :: forall a b (f1 :: * -&gt; *) (f :: * -&gt; *).<br />
     (Functor f, Functor f1) =&gt;<br />
     (a -&gt; b) -&gt; f1 (f a) -&gt; f1 (f b)</p>
<p>*Big3&gt; ((\x -&gt; if x &lt; 5 then Nothing else Just x) ) &gt;&gt;&gt; ((* <img src='http://www.serpentine.com/wordpress/wp-includes/images/smilies/icon_cool.gif' alt='8)' class='wp-smiley' /> ) &gt;&gt;&gt; catMaybes $ [1..12]  </p>
<p>[40,48,56,64,72,80,88,96]</p>
<p>I will have to delve into Parsec module someday, but been having WAY to much fun, mucking about with other things.</p>
<p>Cheers,<br />
gene</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hans van Thiel</title>
		<link>http://www.serpentine.com/blog/2008/02/06/the-basics-of-applicative-functors-put-to-practical-work/comment-page-1/#comment-223956</link>
		<dc:creator>Hans van Thiel</dc:creator>
		<pubDate>Fri, 17 Apr 2009 12:10:16 +0000</pubDate>
		<guid isPermaLink="false">http://www.serpentine.com/blog/2008/02/06/the-basics-of-applicative-functors-put-to-practical-work/#comment-223956</guid>
		<description>But to parse the non-context free string of n &#039;a&#039; followed by n &#039;b&#039; followed by n &#039;c&#039; characters you do need the monadic structure. Example taken from:
&#039;Combinator Parsing: A Short Tutorial&#039; by S.Doaitse Swierstra

p_abc :: CharParser st String
p_abc = do as &lt;- many (char &#039;a&#039;)
                   let n = length as
                   bs &lt;- pnTimes n (char &#039;b&#039;)
                   cs &lt;- pnTimes n (char &#039;c&#039;)
                   return (as ++ bs ++ cs)

pnTimes :: Int -&gt; CharParser st a -&gt; CharParser st [a]
pnTimes 0 p = return []
pnTimes n p = (:) &lt;$&gt; p &lt;*&gt; pnTimes (n-1) p

ApplicativeParsec&gt; parseTest p_abc &quot;aaabbbccc&quot;
&quot;aaabbbccc&quot;</description>
		<content:encoded><![CDATA[<p>But to parse the non-context free string of n &#8216;a&#8217; followed by n &#8216;b&#8217; followed by n &#8216;c&#8217; characters you do need the monadic structure. Example taken from:<br />
&#8216;Combinator Parsing: A Short Tutorial&#8217; by S.Doaitse Swierstra</p>
<p>p_abc :: CharParser st String<br />
p_abc = do as &lt;- many (char &#8216;a&#8217;)<br />
                   let n = length as<br />
                   bs &lt;- pnTimes n (char &#8216;b&#8217;)<br />
                   cs &lt;- pnTimes n (char &#8216;c&#8217;)<br />
                   return (as ++ bs ++ cs)</p>
<p>pnTimes :: Int -&gt; CharParser st a -&gt; CharParser st [a]<br />
pnTimes 0 p = return []<br />
pnTimes n p = (:) &lt;$&gt; p &lt;*&gt; pnTimes (n-1) p</p>
<p>ApplicativeParsec&gt; parseTest p_abc &#8220;aaabbbccc&#8221;<br />
&#8220;aaabbbccc&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hans van Thiel</title>
		<link>http://www.serpentine.com/blog/2008/02/06/the-basics-of-applicative-functors-put-to-practical-work/comment-page-1/#comment-223783</link>
		<dc:creator>Hans van Thiel</dc:creator>
		<pubDate>Thu, 16 Apr 2009 19:27:35 +0000</pubDate>
		<guid isPermaLink="false">http://www.serpentine.com/blog/2008/02/06/the-basics-of-applicative-functors-put-to-practical-work/#comment-223783</guid>
		<description>and forgot all about the &lt; and &gt; escape sequences, also as above. Tss,Tss...sorry!</description>
		<content:encoded><![CDATA[<p>and forgot all about the &lt; and &gt; escape sequences, also as above. Tss,Tss&#8230;sorry!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hans van Thiel</title>
		<link>http://www.serpentine.com/blog/2008/02/06/the-basics-of-applicative-functors-put-to-practical-work/comment-page-1/#comment-223782</link>
		<dc:creator>Hans van Thiel</dc:creator>
		<pubDate>Thu, 16 Apr 2009 19:22:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.serpentine.com/blog/2008/02/06/the-basics-of-applicative-functors-put-to-practical-work/#comment-223782</guid>
		<description>Thanks for this example, which I found through Brent Yorgey&#039;s &#039;The Typeclassopedia&#039; article in &#039;The Monad Reader&#039;, Issue 13.
For those not too familiar with Parsec (like myself), here are some examples, using Hugs:

ApplicativeParsec&gt; parseTest p_query &quot;name=bryan+o%27sullivan&amp;city=san+francisco&quot;
[(&quot;name&quot;,Just &quot;bryan o&#039;sullivan&quot;),(&quot;city&quot;,Just &quot;san francisco&quot;)]

You need the parseTest function to run the example interactively.

ApplicativeParsec&gt; parseTest p_headers &quot;Subject: RFC2822 or HTTP (or MIME, or what have you\n\n&quot;
[(&quot;Subject&quot;,&quot;RFC2822 or HTTP (or MIME, or what have you&quot;)]

Note the 2 newlines at the end, which terminate the input in this text format.

I replaced  the liftA2 in the source code with  and , as explained above.</description>
		<content:encoded><![CDATA[<p>Thanks for this example, which I found through Brent Yorgey&#8217;s &#8216;The Typeclassopedia&#8217; article in &#8216;The Monad Reader&#8217;, Issue 13.<br />
For those not too familiar with Parsec (like myself), here are some examples, using Hugs:</p>
<p>ApplicativeParsec&gt; parseTest p_query &#8220;name=bryan+o%27sullivan&amp;city=san+francisco&#8221;<br />
[("name",Just "bryan o'sullivan"),("city",Just "san francisco")]</p>
<p>You need the parseTest function to run the example interactively.</p>
<p>ApplicativeParsec&gt; parseTest p_headers &#8220;Subject: RFC2822 or HTTP (or MIME, or what have you\n\n&#8221;<br />
[("Subject","RFC2822 or HTTP (or MIME, or what have you")]</p>
<p>Note the 2 newlines at the end, which terminate the input in this text format.</p>
<p>I replaced  the liftA2 in the source code with  and , as explained above.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: augustss</title>
		<link>http://www.serpentine.com/blog/2008/02/06/the-basics-of-applicative-functors-put-to-practical-work/comment-page-1/#comment-122286</link>
		<dc:creator>augustss</dc:creator>
		<pubDate>Thu, 07 Feb 2008 09:38:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.serpentine.com/blog/2008/02/06/the-basics-of-applicative-functors-put-to-practical-work/#comment-122286</guid>
		<description>It&#039;s interesting how the point free style of parser combinators are coming back into vogue after being displaced by monadic combinators for a while.
The point free combinators was how I started  (as pioneered(?) by Burge in &quot;Recursive Programming Techniques&quot; in the 70s).</description>
		<content:encoded><![CDATA[<p>It&#8217;s interesting how the point free style of parser combinators are coming back into vogue after being displaced by monadic combinators for a while.<br />
The point free combinators was how I started  (as pioneered(?) by Burge in &#8220;Recursive Programming Techniques&#8221; in the 70s).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brent Yorgey</title>
		<link>http://www.serpentine.com/blog/2008/02/06/the-basics-of-applicative-functors-put-to-practical-work/comment-page-1/#comment-122174</link>
		<dc:creator>Brent Yorgey</dc:creator>
		<pubDate>Thu, 07 Feb 2008 02:00:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.serpentine.com/blog/2008/02/06/the-basics-of-applicative-functors-put-to-practical-work/#comment-122174</guid>
		<description>Argh! it ate all my angle brackets!  ok, take two, fingers crossed...

Instead of liftA2, you can also use another nice set of Applicative combinators, &lt;$&gt; and &lt;*&gt;.

liftA2 foo x y

becomes

foo &lt;$&gt; x &lt;*&gt; y

One of the nice things about this is that it generalizes easily to liftA3, liftA4, â€¦ that is,

liftAn foo x1 x2 â€¦ xn

becomes

foo &lt;$&gt; x1 &lt;*&gt; x2 &lt;*&gt; â€¦ &lt;*&gt; xn.

(For those who might care, note that &lt;$&gt; is just a synonym for fmap! And &lt;*&gt; applies a function â€œinsideâ€ an applicative to a value inside another applicative.)</description>
		<content:encoded><![CDATA[<p>Argh! it ate all my angle brackets!  ok, take two, fingers crossed&#8230;</p>
<p>Instead of liftA2, you can also use another nice set of Applicative combinators, &lt;$&gt; and &lt;*&gt;.</p>
<p>liftA2 foo x y</p>
<p>becomes</p>
<p>foo &lt;$&gt; x &lt;*&gt; y</p>
<p>One of the nice things about this is that it generalizes easily to liftA3, liftA4, â€¦ that is,</p>
<p>liftAn foo x1 x2 â€¦ xn</p>
<p>becomes</p>
<p>foo &lt;$&gt; x1 &lt;*&gt; x2 &lt;*&gt; â€¦ &lt;*&gt; xn.</p>
<p>(For those who might care, note that &lt;$&gt; is just a synonym for fmap! And &lt;*&gt; applies a function â€œinsideâ€ an applicative to a value inside another applicative.)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brent Yorgey</title>
		<link>http://www.serpentine.com/blog/2008/02/06/the-basics-of-applicative-functors-put-to-practical-work/comment-page-1/#comment-122172</link>
		<dc:creator>Brent Yorgey</dc:creator>
		<pubDate>Thu, 07 Feb 2008 01:58:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.serpentine.com/blog/2008/02/06/the-basics-of-applicative-functors-put-to-practical-work/#comment-122172</guid>
		<description>Instead of liftA2, you can also use another nice set of Applicative combinators,  and .  

liftA2 foo x y

becomes

foo  x  y

One of the nice things about this is that it generalizes easily to liftA3, liftA4, ... that is,

liftAn foo x1 x2 ... xn

becomes

foo  x1  x2  ...  xn.

(For those who might care, note that  is just a synonym for fmap!  And  applies a function &quot;inside&quot; an applicative to a value inside another applicative.)</description>
		<content:encoded><![CDATA[<p>Instead of liftA2, you can also use another nice set of Applicative combinators,  and .  </p>
<p>liftA2 foo x y</p>
<p>becomes</p>
<p>foo  x  y</p>
<p>One of the nice things about this is that it generalizes easily to liftA3, liftA4, &#8230; that is,</p>
<p>liftAn foo x1 x2 &#8230; xn</p>
<p>becomes</p>
<p>foo  x1  x2  &#8230;  xn.</p>
<p>(For those who might care, note that  is just a synonym for fmap!  And  applies a function &#8220;inside&#8221; an applicative to a value inside another applicative.)</p>
]]></content:encoded>
	</item>
</channel>
</rss>

