<?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"
	>
<channel>
	<title>Comments on: More adventures in parsing</title>
	<atom:link href="http://therning.org/magnus/archives/290/feed" rel="self" type="application/rss+xml" />
	<link>http://therning.org/magnus/archives/290?&amp;owa_from=feed&amp;owa_sid=</link>
	<description>Incoherent mumblings</description>
	<pubDate>Sat, 06 Sep 2008 00:04:09 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.1</generator>
		<item>
		<title>By: therning.org/ magnus &#187; Blog Archive &#187; Adventures in parsing, part 3</title>
		<link>http://therning.org/magnus/archives/290#comment-55597</link>
		<dc:creator>therning.org/ magnus &#187; Blog Archive &#187; Adventures in parsing, part 3</dc:creator>
		<pubDate>Sun, 03 Jun 2007 00:24:11 +0000</pubDate>
		<guid isPermaLink="false">http://therning.org/magnus/archives/290#comment-55597</guid>
		<description>&lt;p&gt;[...] got a great many comments, at least by my standards, on my earlier two posts on parsing in Haskell. Especially on the latest one. Conal posted a comment on the first [...]&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>[...] got a great many comments, at least by my standards, on my earlier two posts on parsing in Haskell. Especially on the latest one. Conal posted a comment on the first [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Magnus</title>
		<link>http://therning.org/magnus/archives/290#comment-52880</link>
		<dc:creator>Magnus</dc:creator>
		<pubDate>Wed, 30 May 2007 23:19:40 +0000</pubDate>
		<guid isPermaLink="false">http://therning.org/magnus/archives/290#comment-52880</guid>
		<description>&lt;p&gt;Conal, ok, you're one sneaky little b... ;-) I'll have to look at the applicative operators to see what I think of them.&lt;/p&gt;

&lt;p&gt;Yes, there is a way. I use &lt;a href="http://daringfireball.net/projects/markdown/" rel="nofollow"&gt;markdown&lt;/a&gt; for writing my entries and it works in the comments as well. Besides that certain HTML tags seem to work. In particular &#60;pre&#62; works fine for code.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Conal, ok, you&#8217;re one sneaky little b&#8230; <img src='http://therning.org/magnus/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> I&#8217;ll have to look at the applicative operators to see what I think of them.</p>
<p>Yes, there is a way. I use <a href="http://daringfireball.net/projects/markdown/" rel="nofollow">markdown</a> for writing my entries and it works in the comments as well. Besides that certain HTML tags seem to work. In particular &lt;pre&gt; works fine for code.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Magnus</title>
		<link>http://therning.org/magnus/archives/290#comment-52879</link>
		<dc:creator>Magnus</dc:creator>
		<pubDate>Wed, 30 May 2007 23:08:42 +0000</pubDate>
		<guid isPermaLink="false">http://therning.org/magnus/archives/290#comment-52879</guid>
		<description>&lt;p&gt;Nick, yes your way of writing it is easier to read. You'll need to change to using &lt;code&gt;&#62;&#62;=&lt;/code&gt; though:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;do
    start &#60;- many1 hexDigit &#62;&#62;= aChar '-'
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Then you can mix in &lt;code&gt;liftM&lt;/code&gt; as well:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;do
    start &#60;- liftM hexStr2Int $ many1 hexDigit &#62;&#62;= aChar '-'
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;to do the conversion. However, I think my initial version is even clearer:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;do
    start &#60;- liftM hexStr2Int $ many1 hexDigitc
    char '-'
&lt;/code&gt;&lt;/pre&gt;
</description>
		<content:encoded><![CDATA[<p>Nick, yes your way of writing it is easier to read. You&#8217;ll need to change to using <code>&gt;&gt;=</code> though:</p>
<pre><code>do
    start &lt;- many1 hexDigit &gt;&gt;= aChar '-'
</code></pre>
<p>Then you can mix in <code>liftM</code> as well:</p>
<pre><code>do
    start &lt;- liftM hexStr2Int $ many1 hexDigit &gt;&gt;= aChar '-'
</code></pre>
<p>to do the conversion. However, I think my initial version is even clearer:</p>
<pre><code>do
    start &lt;- liftM hexStr2Int $ many1 hexDigitc
    char '-'
</code></pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Twan van Laarhoven</title>
		<link>http://therning.org/magnus/archives/290#comment-52870</link>
		<dc:creator>Twan van Laarhoven</dc:creator>
		<pubDate>Wed, 30 May 2007 22:42:36 +0000</pubDate>
		<guid isPermaLink="false">http://therning.org/magnus/archives/290#comment-52870</guid>
		<description>&lt;p&gt;&#38;lt; should produce "&#60;".
So: liftM3 f x y z == f &#60;$&#62; x &#60;&lt;em&gt;&#62; y &#60;&lt;/em&gt;&#62; z&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>&amp;lt; should produce &#8220;&lt;&#8221;.<br />
So: liftM3 f x y z == f &lt;$&gt; x &lt;<em>&gt; y &lt;</em>&gt; z</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Conal Elliott</title>
		<link>http://therning.org/magnus/archives/290#comment-52689</link>
		<dc:creator>Conal Elliott</dc:creator>
		<pubDate>Wed, 30 May 2007 19:06:31 +0000</pubDate>
		<guid isPermaLink="false">http://therning.org/magnus/archives/290#comment-52689</guid>
		<description>&lt;p&gt;yes, that's exactly the direction i had in mind.  once you switch from "do" style to "liftM#" style, it's a simple step to replace the monad operators to applicative functor operators.&lt;/p&gt;

&lt;p&gt;the previous comments have lost many operators in the blog conversion.  is there a way to get code through safely, including operators that look html tags?&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>yes, that&#8217;s exactly the direction i had in mind.  once you switch from &#8220;do&#8221; style to &#8220;liftM#&#8221; style, it&#8217;s a simple step to replace the monad operators to applicative functor operators.</p>
<p>the previous comments have lost many operators in the blog conversion.  is there a way to get code through safely, including operators that look html tags?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nick</title>
		<link>http://therning.org/magnus/archives/290#comment-52641</link>
		<dc:creator>Nick</dc:creator>
		<pubDate>Wed, 30 May 2007 18:13:29 +0000</pubDate>
		<guid isPermaLink="false">http://therning.org/magnus/archives/290#comment-52641</guid>
		<description>&lt;p&gt;I find the "thenSpace" a bit difficult to read.I think something like this is more natural, as it maintains the left-to-right relationship of the parsed data and the following space:&lt;/p&gt;

&lt;p&gt;aChar c r = char c &#62;&#62; return r
aSpace = aChar ' '&lt;/p&gt;

&lt;p&gt;...
    do
        start &#60;-  many1 hexDigit &#62;&#62; aChar
....&lt;/p&gt;

&lt;p&gt;note that I haven't tested this and my haskell-fu is not very strong, so I could be way off here.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>I find the &#8220;thenSpace&#8221; a bit difficult to read.I think something like this is more natural, as it maintains the left-to-right relationship of the parsed data and the following space:</p>
<p>aChar c r = char c &gt;&gt; return r<br />
aSpace = aChar &#8216; &#8216;</p>
<p>&#8230;<br />
    do<br />
        start &lt;-  many1 hexDigit &gt;&gt; aChar<br />
&#8230;.</p>
<p>note that I haven&#8217;t tested this and my haskell-fu is not very strong, so I could be way off here.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Twan van Laarhoven</title>
		<link>http://therning.org/magnus/archives/290#comment-52569</link>
		<dc:creator>Twan van Laarhoven</dc:creator>
		<pubDate>Wed, 30 May 2007 16:33:41 +0000</pubDate>
		<guid isPermaLink="false">http://therning.org/magnus/archives/290#comment-52569</guid>
		<description>&lt;p&gt;The best way to make parsing code readable is to use Data.Applicative. Also, most people prefer where to let..in if possible. This gives something like:&lt;/p&gt;

&lt;pre&gt;
parseHexStr = Prelude.read . ("0x" ++)  many1 hexDigit
parsePath   = many1 (char ' ') *&#62; many1 anyChar

parseAddress = Address  hexStr *&#62; char '-'  hexStr 

parseRegion = MemRegion
            parseAddress *&#62; char ' '
            parsePerms   *&#62; char ' '
            parseHexStr  *&#62; char ' '
            parseDevice  *&#62; char ' '
            (Prelude.read  many1 digit) *&#62; char ' '
            (parsePath  return "")
&lt;/pre&gt;

&lt;p&gt;Basicly (liftM# f x y z) can be written as "f  x &#60;&lt;em&gt;&#62; y &#60;&lt;/em&gt;&#62; z".&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>The best way to make parsing code readable is to use Data.Applicative. Also, most people prefer where to let..in if possible. This gives something like:</p>
<pre>
parseHexStr = Prelude.read . ("0x" ++)  many1 hexDigit
parsePath   = many1 (char ' ') *&gt; many1 anyChar

parseAddress = Address  hexStr *&gt; char '-'  hexStr 

parseRegion = MemRegion
            parseAddress *&gt; char ' '
            parsePerms   *&gt; char ' '
            parseHexStr  *&gt; char ' '
            parseDevice  *&gt; char ' '
            (Prelude.read  many1 digit) *&gt; char ' '
            (parsePath  return "")
</pre>
<p>Basicly (liftM# f x y z) can be written as &#8220;f  x &lt;<em>&gt; y &lt;</em>&gt; z&#8221;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Cale Gibbard</title>
		<link>http://therning.org/magnus/archives/290#comment-52530</link>
		<dc:creator>Cale Gibbard</dc:creator>
		<pubDate>Wed, 30 May 2007 15:30:07 +0000</pubDate>
		<guid isPermaLink="false">http://therning.org/magnus/archives/290#comment-52530</guid>
		<description>&lt;p&gt;liftM2 guarantees an ordering on the monadic computation, because it's defined like:&lt;/p&gt;

&lt;p&gt;liftM2 f x y = do { u &#60;- x; v &#60;- y; return (f u v) }&lt;/p&gt;

&lt;p&gt;Though, that's a little different from guaranteeing an order of evaluation -- depending on the monad, the order of evaluation will vary. In any case, it shouldn't be much different from what you originally had.&lt;/p&gt;

&lt;p&gt;Another thing you might like to play around with, at least in your head, is the fact that:&lt;/p&gt;

&lt;p&gt;liftM2 f x y = return f &lt;code&gt;ap&lt;/code&gt; x &lt;code&gt;ap&lt;/code&gt; y&lt;/p&gt;

&lt;p&gt;liftM3 f x y z = return f &lt;code&gt;ap&lt;/code&gt; x &lt;code&gt;ap&lt;/code&gt; y &lt;code&gt;ap&lt;/code&gt; z&lt;/p&gt;

&lt;p&gt;and so on, which leads up to the style embodied by the Control.Applicative library, though if you really want to play around with that, you'll need to write a quick instance of Applicative for GenParser, which should just consist of making pure = return and (&#60;*&#62;) = ap.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>liftM2 guarantees an ordering on the monadic computation, because it&#8217;s defined like:</p>
<p>liftM2 f x y = do { u &lt;- x; v &lt;- y; return (f u v) }</p>
<p>Though, that&#8217;s a little different from guaranteeing an order of evaluation &#8212; depending on the monad, the order of evaluation will vary. In any case, it shouldn&#8217;t be much different from what you originally had.</p>
<p>Another thing you might like to play around with, at least in your head, is the fact that:</p>
<p>liftM2 f x y = return f <code>ap</code> x <code>ap</code> y</p>
<p>liftM3 f x y z = return f <code>ap</code> x <code>ap</code> y <code>ap</code> z</p>
<p>and so on, which leads up to the style embodied by the Control.Applicative library, though if you really want to play around with that, you&#8217;ll need to write a quick instance of Applicative for GenParser, which should just consist of making pure = return and (&lt;*&gt;) = ap.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Holger</title>
		<link>http://therning.org/magnus/archives/290#comment-52522</link>
		<dc:creator>Holger</dc:creator>
		<pubDate>Wed, 30 May 2007 15:11:55 +0000</pubDate>
		<guid isPermaLink="false">http://therning.org/magnus/archives/290#comment-52522</guid>
		<description>&lt;p&gt;I just looked at the source of liftM2/3 and it seems that it basically just resolves to an expression in do-notation. So it's just a shortcut and therefore should yield the same program.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>I just looked at the source of liftM2/3 and it seems that it basically just resolves to an expression in do-notation. So it&#8217;s just a shortcut and therefore should yield the same program.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Magnus</title>
		<link>http://therning.org/magnus/archives/290#comment-52495</link>
		<dc:creator>Magnus</dc:creator>
		<pubDate>Wed, 30 May 2007 13:59:57 +0000</pubDate>
		<guid isPermaLink="false">http://therning.org/magnus/archives/290#comment-52495</guid>
		<description>&lt;p&gt;Yeah, the same line of thought made it a little difficult to fall asleep yesterday (yes, I know, nerdiness taken to new levels). My thoughts was something like this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;parseAddress = let
        hexStr2Int = ...
    in
        liftM2 Address 
            (liftM hexStr2Int $ thenChar '-' $ many1 hexDigit)
            (liftM hexStr2Int $ many1 hexDigit)
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;I agree with you on readability. I also wonder if laziness could bite back or if &lt;code&gt;liftM2&lt;/code&gt; guarantees an order of evaluation.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Yeah, the same line of thought made it a little difficult to fall asleep yesterday (yes, I know, nerdiness taken to new levels). My thoughts was something like this:</p>
<pre><code>parseAddress = let
        hexStr2Int = ...
    in
        liftM2 Address
            (liftM hexStr2Int $ thenChar '-' $ many1 hexDigit)
            (liftM hexStr2Int $ many1 hexDigit)
</code></pre>
<p>I agree with you on readability. I also wonder if laziness could bite back or if <code>liftM2</code> guarantees an order of evaluation.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
