<?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: 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</link>
	<description>Incoherent mumblings</description>
	<lastBuildDate>Fri, 09 Dec 2011 20:40:28 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</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-page-1#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-page-1#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&#039;re one sneaky little b... ;-) I&#039;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=&quot;http://daringfireball.net/projects/markdown/&quot; rel=&quot;nofollow&quot;&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 &lt;pre&gt; 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-page-1#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&#039;ll need to change to using &lt;code&gt;&gt;&gt;=&lt;/code&gt; though:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;do
    start &lt;- many1 hexDigit &gt;&gt;= aChar &#039;-&#039;
&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 &lt;- liftM hexStr2Int $ many1 hexDigit &gt;&gt;= aChar &#039;-&#039;
&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 &lt;- liftM hexStr2Int $ many1 hexDigitc
    char &#039;-&#039;
&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-page-1#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;&lt; should produce &quot;&lt;&quot;.
So: liftM3 f x y z == f &lt;$&gt; x &lt;&lt;em&gt;&gt; y &lt;&lt;/em&gt;&gt; z&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>&amp;lt; should produce &#8220;&lt;&#8221;.
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-page-1#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&#039;s exactly the direction i had in mind.  once you switch from &quot;do&quot; style to &quot;liftM#&quot; style, it&#039;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-page-1#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 &quot;thenSpace&quot; 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 &gt;&gt; return r
aSpace = aChar &#039; &#039;&lt;/p&gt;

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

&lt;p&gt;note that I haven&#039;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
aSpace = aChar &#8216; &#8216;</p>

<p>&#8230;
    do
        start &lt;-  many1 hexDigit &gt;&gt; aChar
&#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-page-1#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 . (&quot;0x&quot; ++)  many1 hexDigit
parsePath   = many1 (char &#039; &#039;) *&gt; many1 anyChar

parseAddress = Address  hexStr *&gt; char &#039;-&#039;  hexStr 

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

&lt;p&gt;Basicly (liftM# f x y z) can be written as &quot;f  x &lt;&lt;em&gt;&gt; y &lt;&lt;/em&gt;&gt; z&quot;.&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-page-1#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&#039;s defined like:&lt;/p&gt;

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

&lt;p&gt;Though, that&#039;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&#039;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&#039;ll need to write a quick instance of Applicative for GenParser, which should just consist of making pure = return and (&lt;*&gt;) = 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-page-1#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&#039;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-page-1#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 &#039;-&#039; $ 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>
	<item>
		<title>By: Holger</title>
		<link>http://therning.org/magnus/archives/290/comment-page-1#comment-52430</link>
		<dc:creator>Holger</dc:creator>
		<pubDate>Wed, 30 May 2007 12:15:48 +0000</pubDate>
		<guid isPermaLink="false">http://therning.org/magnus/archives/290#comment-52430</guid>
		<description>&lt;p&gt;Hi,&lt;/p&gt;

&lt;p&gt;your story and Conal&#039;s comment inspired me to play around with liftM and I came up with this version of parseAddress:&lt;/p&gt;

&lt;p&gt;parseAddress = let
        hexStr2Int = Prelude.read . (&quot;0x&quot; ++)
    in 
        liftM3 (x _ y -&gt; Address (hexStr2Int x) (hexStr2Int y)) (many1 hexDigit) (char &#039;-&#039;) (many1 hexDigit)&lt;/p&gt;

&lt;p&gt;You could probably rewrite all the functions in a similar way, but honestly I find your original code in do-notation much easier to read.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Hi,</p>

<p>your story and Conal&#8217;s comment inspired me to play around with liftM and I came up with this version of parseAddress:</p>

<p>parseAddress = let
        hexStr2Int = Prelude.read . (&#8220;0x&#8221; ++)
    in 
        liftM3 (x _ y -&gt; Address (hexStr2Int x) (hexStr2Int y)) (many1 hexDigit) (char &#8216;-&#8217;) (many1 hexDigit)</p>

<p>You could probably rewrite all the functions in a similar way, but honestly I find your original code in do-notation much easier to read.</p>]]></content:encoded>
	</item>
</channel>
</rss>

