<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>therning.org/ magnus</title>
	<atom:link href="http://therning.org/magnus/feed" rel="self" type="application/rss+xml" />
	<link>http://therning.org/magnus</link>
	<description>Incoherent mumblings</description>
	<lastBuildDate>Sun, 29 Aug 2010 21:59:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Dent Weekly Updates for 2010-08-29</title>
		<link>http://therning.org/magnus/archives/873</link>
		<comments>http://therning.org/magnus/archives/873#comments</comments>
		<pubDate>Sun, 29 Aug 2010 21:59:00 +0000</pubDate>
		<dc:creator>Magnus</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[dents]]></category>

		<guid isPermaLink="false">http://therning.org/magnus/archives/873</guid>
		<description><![CDATA[I wonder when people will stop referring to &#34;windows&#34; as &#34;pc&#34;. # &#34;You can&#039;t drown you fool! You&#039;re immortal.&#34; # Just added HTTP Everywhere to firefox, thanks @jsk # Now I&#039;ve prepared my vote, I just have to remember to send it off. # Yay, unsubscribing myself from #cmake ml. # Made it public that [...]]]></description>
			<content:encoded><![CDATA[<ul class="aktt_tweet_digest">
    <li>I wonder when people will stop referring to &quot;windows&quot; as &quot;pc&quot;. <a href="http://identi.ca/api/magthe/statuses/47142112" class="aktt_tweet_time">#</a></li>
    <li>&quot;You can&#039;t drown you fool! You&#039;re immortal.&quot; <a href="http://identi.ca/api/magthe/statuses/47194495" class="aktt_tweet_time">#</a></li>
    <li>Just added HTTP Everywhere to firefox, thanks @<a href="http://identi.ca/api/jsk" class="aktt_username">jsk</a> <a href="http://identi.ca/api/magthe/statuses/47399761" class="aktt_tweet_time">#</a></li>
    <li>Now I&#039;ve prepared my vote, I just have to remember to send it off. <a href="http://identi.ca/api/magthe/statuses/47402268" class="aktt_tweet_time">#</a></li>
    <li>Yay, unsubscribing myself from #<a href="http://search.identi.ca/api/search.json?q=%23cmake" class="aktt_hashtag">cmake</a> ml. <a href="http://identi.ca/api/magthe/statuses/47410593" class="aktt_tweet_time">#</a></li>
    <li>Made it public that I have no intentions of doing anything more with CMake-OCaml #<a href="http://search.identi.ca/api/search.json?q=%23cmake" class="aktt_hashtag">cmake</a> #github <a href="http://identi.ca/api/magthe/statuses/47444802" class="aktt_tweet_time">#</a></li>
    <li>Något som alla borde läsa, nu när det är valtider: <a href="http://blogs.berkeley.edu/2010/08/24/a-letter-to-my-students/" rel="nofollow">http://blogs.berkeley.edu/2010/08/24/a-letter-to-my-students/</a> <a href="http://identi.ca/api/magthe/statuses/47499663" class="aktt_tweet_time">#</a></li>
    <li>Everyone should read this: <a href="http://blogs.berkeley.edu/2010/08/24/a-letter-to-my-students/" rel="nofollow">http://blogs.berkeley.edu/2010/08/24/a-letter-to-my-students/</a> <a href="http://identi.ca/api/magthe/statuses/47499681" class="aktt_tweet_time">#</a></li>
    <li>For UK residents: <a href="http://labs.38degrees.org.uk/wall/NHS" rel="nofollow">http://labs.38degrees.org.uk/wall/NHS</a> <a href="http://identi.ca/api/magthe/statuses/47661445" class="aktt_tweet_time">#</a></li>
    <li>Is there an example of how to use reflect (<a href="http://hackage.haskell.org/package/reflection)?" rel="nofollow">http://hackage.haskell.org/package/reflection)?</a> #<a href="http://search.identi.ca/api/search.json?q=%23haskell" class="aktt_hashtag">haskell</a> <a href="http://identi.ca/api/magthe/statuses/47836671" class="aktt_tweet_time">#</a></li>
</ul>

<p class="aktt_credit">Powered by <a href="http://alexking.org/projects/wordpress">Twitter Tools</a></p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Bookmark</a> </p>]]></content:encoded>
			<wfw:commentRss>http://therning.org/magnus/archives/873/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dent Weekly Updates for 2010-08-22</title>
		<link>http://therning.org/magnus/archives/872</link>
		<comments>http://therning.org/magnus/archives/872#comments</comments>
		<pubDate>Sun, 22 Aug 2010 21:59:00 +0000</pubDate>
		<dc:creator>Magnus</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[dents]]></category>

		<guid isPermaLink="false">http://therning.org/magnus/archives/872</guid>
		<description><![CDATA[#ubuntu devs, what are you smoking? the netbook remix includes cups! WTF? # Have now heavily modified some Ubuntu packages to remove the more insane bits: openoffice, cups, f-spot, tomboy # Yay, finally gotten some of the craziness out of #ubuntu netbook remix. Still a few things remaining, but much better now. # I never [...]]]></description>
			<content:encoded><![CDATA[<ul class="aktt_tweet_digest">
    <li>#<a href="http://search.identi.ca/api/search.json?q=%23ubuntu" class="aktt_hashtag">ubuntu</a> devs, what are you smoking? the netbook remix includes cups! WTF? <a href="http://identi.ca/api/magthe/statuses/46311277" class="aktt_tweet_time">#</a></li>
    <li>Have now heavily modified some Ubuntu packages to remove the more insane bits: openoffice, cups, f-spot, tomboy <a href="http://identi.ca/api/magthe/statuses/46337331" class="aktt_tweet_time">#</a></li>
    <li>Yay, finally gotten some of the craziness out of #<a href="http://search.identi.ca/api/search.json?q=%23ubuntu" class="aktt_hashtag">ubuntu</a> netbook remix. Still a few things remaining, but much better now. <a href="http://identi.ca/api/magthe/statuses/46389382" class="aktt_tweet_time">#</a></li>
    <li>I never manage to get empathy to work on #<a href="http://search.identi.ca/api/search.json?q=%23arch" class="aktt_hashtag">arch</a>  not sure why. <a href="http://identi.ca/api/magthe/statuses/46466337" class="aktt_tweet_time">#</a></li>
    <li>It&#039;s painfully slow to download #<a href="http://search.identi.ca/api/search.json?q=%23PaulDotCom" class="aktt_hashtag">PaulDotCom</a> e206 this morning! <a href="http://identi.ca/api/magthe/statuses/46543043" class="aktt_tweet_time">#</a></li>
    <li>I now have #<a href="http://search.identi.ca/api/search.json?q=%23empathy" class="aktt_hashtag">empathy</a> working at work, at least a bit, no luck with using #<a href="http://search.identi.ca/api/search.json?q=%23pidgin" class="aktt_hashtag">pidgin</a> #039;s sipe though <img src='http://therning.org/magnus/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' />  <a href="http://identi.ca/api/magthe/statuses/46556423" class="aktt_tweet_time">#</a></li>
    <li>I really don&#039;t like when people cancel a meeting 2 minuntes before it starts! <a href="http://identi.ca/api/magthe/statuses/46596189" class="aktt_tweet_time">#</a></li>
    <li>World map of happiness: <a href="http://www.sciencedaily.com/releases/2006/11/061113093726.htm" rel="nofollow">http://www.sciencedaily.com/releases/2006/11/061113093726.htm</a> (well, not really a map, an article about such a map) <a href="http://identi.ca/api/magthe/statuses/46774217" class="aktt_tweet_time">#</a></li>
    <li>#<a href="http://search.identi.ca/api/search.json?q=%23microsoft" class="aktt_hashtag">microsoft</a>  really, it&#039;s 2010!!! How difficult is it to make re-sizable dialogue boxes? <a href="http://identi.ca/api/magthe/statuses/46785430" class="aktt_tweet_time">#</a></li>
    <li>What a straw man argument! I was expecting better: <a href="http://theinvisiblethings.blogspot.com/2010/08/ms-dos-security-model.html" rel="nofollow">http://theinvisiblethings.blogspot.com/2010/08/ms-dos-security-model.html</a> <a href="http://identi.ca/api/magthe/statuses/46804788" class="aktt_tweet_time">#</a></li>
    <li>Yay, managed to remove the use of MissingH in a #<a href="http://search.identi.ca/api/search.json?q=%23haskell" class="aktt_hashtag">haskell</a> tool. That&#039;s always a good thing <img src='http://therning.org/magnus/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  <a href="http://identi.ca/api/magthe/statuses/46824322" class="aktt_tweet_time">#</a></li>
    <li>I suspect I&#039;ve found a bug in cmdargs 0.2, however it only manifests itself when building with Cabal. Very strange. #<a href="http://search.identi.ca/api/search.json?q=%23haskell" class="aktt_hashtag">haskell</a> <a href="http://identi.ca/api/magthe/statuses/46833210" class="aktt_tweet_time">#</a></li>
    <li>Ouch, vimoutliner can&#039;t be downloaded from the project site, just when I really could need it <img src='http://therning.org/magnus/wp-includes/images/smilies/icon_sad.gif' alt=':-(' class='wp-smiley' />  Anyone out there who has a copy to share? <a href="http://identi.ca/api/magthe/statuses/46947832" class="aktt_tweet_time">#</a></li>
    <li>I wonder if it&#039;s the upgrade to #<a href="http://search.identi.ca/api/search.json?q=%23ocaml" class="aktt_hashtag">ocaml</a> 3.12 that broke the building of ocaml-data-notation. <a href="http://identi.ca/api/magthe/statuses/46953116" class="aktt_tweet_time">#</a></li>
    <li>I&#039;ve finally gotten around to finding out how to build #<a href="http://search.identi.ca/api/search.json?q=%23archlinux" class="aktt_hashtag">archlinux</a> packages in a chroot. <a href="http://identi.ca/api/magthe/statuses/46954069" class="aktt_tweet_time">#</a></li>
    <li>Worth watching for anyone using functional languages: <a href="http://vimeo.com/14313378" rel="nofollow">http://vimeo.com/14313378</a> <a href="http://identi.ca/api/magthe/statuses/47009587" class="aktt_tweet_time">#</a></li>
    <li>I&#039;m reading complaints from devs running Windows that they need to install a Unix emulator to use Haskell. I love it! <a href="http://identi.ca/api/magthe/statuses/47045827" class="aktt_tweet_time">#</a></li>
</ul>

<p class="aktt_credit">Powered by <a href="http://alexking.org/projects/wordpress">Twitter Tools</a></p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Bookmark</a> </p>]]></content:encoded>
			<wfw:commentRss>http://therning.org/magnus/archives/872/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Dent Weekly Updates for 2010-08-15</title>
		<link>http://therning.org/magnus/archives/871</link>
		<comments>http://therning.org/magnus/archives/871#comments</comments>
		<pubDate>Sun, 15 Aug 2010 21:59:00 +0000</pubDate>
		<dc:creator>Magnus</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[dents]]></category>

		<guid isPermaLink="false">http://therning.org/magnus/archives/871</guid>
		<description><![CDATA[Thanks! http://code.google.com/p/ndmitchell/issues/detail?id=231 # Why APIs matter: http://www.youtube.com/watch?v=aAb7hSCtvGw # Brilliant: http://thechive.com/2010/08/10/girl-quits-her-job-on-dry-erase-board-emails-entire-office-33-photos/ # I wish I could feel sorry about Wave going away, but I never had a chance to really get into it; not enough friends using it # #tempita is a nice little templating language for #python http://pythonpaste.org/tempita/ # The only thing airline security seems [...]]]></description>
			<content:encoded><![CDATA[<ul class="aktt_tweet_digest">
    <li>Thanks! <a href="http://code.google.com/p/ndmitchell/issues/detail?id=231" rel="nofollow">http://code.google.com/p/ndmitchell/issues/detail?id=231</a> <a href="http://identi.ca/api/magthe/statuses/45568012" class="aktt_tweet_time">#</a></li>
    <li>Why APIs matter: <a href="http://www.youtube.com/watch?v=aAb7hSCtvGw" rel="nofollow">http://www.youtube.com/watch?v=aAb7hSCtvGw</a> <a href="http://identi.ca/api/magthe/statuses/45643429" class="aktt_tweet_time">#</a></li>
    <li>Brilliant: <a href="http://thechive.com/2010/08/10/girl-quits-her-job-on-dry-erase-board-emails-entire-office-33-photos/" rel="nofollow">http://thechive.com/2010/08/10/girl-quits-her-job-on-dry-erase-board-emails-entire-office-33-photos/</a> <a href="http://identi.ca/api/magthe/statuses/45690447" class="aktt_tweet_time">#</a></li>
    <li>I wish I could feel sorry about Wave going away, but I never had a chance to really get into it; not enough friends using it <img src='http://therning.org/magnus/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' />  <a href="http://identi.ca/api/magthe/statuses/45759517" class="aktt_tweet_time">#</a></li>
    <li>#<a href="http://search.identi.ca/api/search.json?q=%23tempita" class="aktt_hashtag">tempita</a> is a nice little templating language for #<a href="http://search.identi.ca/api/search.json?q=%23python" class="aktt_hashtag">python</a>  <a href="http://pythonpaste.org/tempita/" rel="nofollow">http://pythonpaste.org/tempita/</a> <a href="http://identi.ca/api/magthe/statuses/45806421" class="aktt_tweet_time">#</a></li>
    <li>The only thing airline security seems to be good for nowadays is comedy: <a href="http://tinyurl.com/34ctp9o" rel="nofollow">http://tinyurl.com/34ctp9o</a> <a href="http://identi.ca/api/magthe/statuses/45898118" class="aktt_tweet_time">#</a></li>
    <li>Amazing about Japanese 100+yo: <a href="http://www.gp.se/nyheter/varlden/1.424095-200-japanska-hundraaringar-forsvunna" rel="nofollow">http://www.gp.se/nyheter/varlden/1.424095-200-japanska-hundraaringar-forsvunna</a> (in Swedish) <a href="http://identi.ca/api/magthe/statuses/45901589" class="aktt_tweet_time">#</a></li>
    <li>#<a href="http://search.identi.ca/api/search.json?q=%23git" class="aktt_hashtag">git</a> does allow for some really cool things: <a href="http://ben.straubnet.net/post/939181602/git-grafting-repositories" rel="nofollow">http://ben.straubnet.net/post/939181602/git-grafting-repositories</a> <a href="http://identi.ca/api/magthe/statuses/45904436" class="aktt_tweet_time">#</a></li>
    <li>Yay, #<a href="http://search.identi.ca/api/search.json?q=%23ghc" class="aktt_hashtag">ghc</a> 6.12.3 has made it into #<a href="http://search.identi.ca/api/search.json?q=%23arch" class="aktt_hashtag">arch</a> testing. <a href="http://identi.ca/api/magthe/statuses/45923328" class="aktt_tweet_time">#</a></li>
    <li>This is worrying: <a href="http://www.bbc.co.uk/news/education-10820033" rel="nofollow">http://www.bbc.co.uk/news/education-10820033</a> <a href="http://identi.ca/api/magthe/statuses/46005113" class="aktt_tweet_time">#</a></li>
    <li>Cool stuff, online LaTeX: <a href="http://docs.latexlab.org/" rel="nofollow">http://docs.latexlab.org/</a> <a href="http://identi.ca/api/magthe/statuses/46006351" class="aktt_tweet_time">#</a></li>
    <li>Another cool LaTeX tool: <a href="http://detexify.kirelabs.org/classify.html" rel="nofollow">http://detexify.kirelabs.org/classify.html</a> <a href="http://identi.ca/api/magthe/statuses/46007420" class="aktt_tweet_time">#</a></li>
    <li>New version of vim-scripts-haskellmode uploaded to #<a href="http://search.identi.ca/api/search.json?q=%23aur" class="aktt_hashtag">aur</a> <a href="http://identi.ca/api/magthe/statuses/46077500" class="aktt_tweet_time">#</a></li>
    <li>Galet: <a href="http://www.gp.se/nyheter/varlden/1.425640-svenskens-boter-7-7-miljoner" rel="nofollow">http://www.gp.se/nyheter/varlden/1.425640-svenskens-boter-7-7-miljoner</a> <a href="http://identi.ca/api/magthe/statuses/46223508" class="aktt_tweet_time">#</a></li>
    <li>&quot;stty size | read height width&quot; works in zsh but not in bash, why not? <a href="http://identi.ca/api/magthe/statuses/46248075" class="aktt_tweet_time">#</a></li>
    <li>Well, I don&#039;t have a definitive answer, but using &#039;set &#8212; $(stty size)&#039; seems to be the way to do it. <a href="http://identi.ca/api/magthe/statuses/46268963" class="aktt_tweet_time">#</a></li>
</ul>

<p class="aktt_credit">Powered by <a href="http://alexking.org/projects/wordpress">Twitter Tools</a></p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Bookmark</a> </p>]]></content:encoded>
			<wfw:commentRss>http://therning.org/magnus/archives/871/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>XML character dereferencer</title>
		<link>http://therning.org/magnus/archives/828</link>
		<comments>http://therning.org/magnus/archives/828#comments</comments>
		<pubDate>Fri, 13 Aug 2010 14:30:38 +0000</pubDate>
		<dc:creator>Magnus</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://therning.org/magnus/?p=828</guid>
		<description><![CDATA[Just in case you ever need one: xmlCharDeref :: String -&#62; String xmlCharDeref &#91;&#93; = &#91;&#93; xmlCharDeref &#40;'&#38;':'#':'x':r&#41; = let &#40;digits, remainder&#41; = span &#40;/= ';'&#41; r c = chr &#40;read &#40;&#34;0x&#34; ++ digits&#41;&#41; in c : xmlCharDeref &#40;tail remainder&#41; xmlCharDeref &#40;'&#38;':'#':r&#41; = let &#40;digits, remainder&#41; = span &#40;/= ';'&#41; r c = chr &#40;read [...]]]></description>
			<content:encoded><![CDATA[<p>Just in case you ever need one:</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">xmlCharDeref <span style="color: #339933; font-weight: bold;">::</span> <span style="color: #cccc00; font-weight: bold;">String</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: #cccc00; font-weight: bold;">String</span>
xmlCharDeref <span style="color: green;">&#91;</span><span style="color: green;">&#93;</span> <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#91;</span><span style="color: green;">&#93;</span>
xmlCharDeref <span style="color: green;">&#40;</span>'&amp;':'#':'x':r<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">let</span>
        <span style="color: green;">&#40;</span>digits<span style="color: #339933; font-weight: bold;">,</span> remainder<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> <span style="font-weight: bold;">span</span> <span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">/=</span> ';'<span style="color: green;">&#41;</span> r
        c <span style="color: #339933; font-weight: bold;">=</span> chr <span style="color: green;">&#40;</span><span style="font-weight: bold;">read</span> <span style="color: green;">&#40;</span><span style="background-color: #3cb371;">&quot;0x&quot;</span> <span style="color: #339933; font-weight: bold;">++</span> digits<span style="color: green;">&#41;</span><span style="color: green;">&#41;</span>
    <span style="color: #06c; font-weight: bold;">in</span>
        c : xmlCharDeref <span style="color: green;">&#40;</span><span style="font-weight: bold;">tail</span> remainder<span style="color: green;">&#41;</span>
xmlCharDeref <span style="color: green;">&#40;</span>'&amp;':'#':r<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">let</span>
        <span style="color: green;">&#40;</span>digits<span style="color: #339933; font-weight: bold;">,</span> remainder<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> <span style="font-weight: bold;">span</span> <span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">/=</span> ';'<span style="color: green;">&#41;</span> r
        c <span style="color: #339933; font-weight: bold;">=</span> chr <span style="color: green;">&#40;</span><span style="font-weight: bold;">read</span> digits<span style="color: green;">&#41;</span>
    <span style="color: #06c; font-weight: bold;">in</span>
        c : xmlCharDeref <span style="color: green;">&#40;</span><span style="font-weight: bold;">tail</span> remainder<span style="color: green;">&#41;</span>
xmlCharDeref <span style="color: green;">&#40;</span>c:r<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> c : xmlCharDeref r</pre></div></div>


<p>In ghci:</p>


<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">*Foo&gt; xmlCharDeref &quot;hello there&quot;
&quot;hello there&quot;
*Foo&gt; xmlCharDeref &quot;hello&amp;#32;there&quot;
&quot;hello there&quot;
*Foo&gt; xmlCharDeref &quot;hello&amp;#x32;there&quot;
&quot;hello2there&quot;</pre></div></div>

<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Bookmark</a> </p>]]></content:encoded>
			<wfw:commentRss>http://therning.org/magnus/archives/828/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Dent Weekly Updates for 2010-08-08</title>
		<link>http://therning.org/magnus/archives/863</link>
		<comments>http://therning.org/magnus/archives/863#comments</comments>
		<pubDate>Sun, 08 Aug 2010 21:59:00 +0000</pubDate>
		<dc:creator>Magnus</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[dents]]></category>

		<guid isPermaLink="false">http://therning.org/magnus/archives/863</guid>
		<description><![CDATA[#ocaml craziness, &#039;land&#039; is infix, so &#34;land;;&#34; gives a syntax error, &#34;(land);;&#34; is what you want, but docs don&#039;t mention this!!! # Yay, another vim extension on #aur that can be removed since upstream releases as VBA; vim-scripts-xmledit # Surely it&#039;s a bit silly that the username counts in replies! # ? @johnnieingram: I&#039;m trying [...]]]></description>
			<content:encoded><![CDATA[<ul class="aktt_tweet_digest">
    <li>#<a href="http://search.identi.ca/api/search.json?q=%23ocaml" class="aktt_hashtag">ocaml</a> craziness, &#039;land&#039; is infix, so &quot;land;;&quot; gives a syntax error, &quot;(land);;&quot; is what you want, but docs don&#039;t mention this!!! <a href="http://identi.ca/api/magthe/statuses/44808795" class="aktt_tweet_time">#</a></li>
    <li>Yay, another vim extension on #<a href="http://search.identi.ca/api/search.json?q=%23aur" class="aktt_hashtag">aur</a> that can be removed since upstream releases as VBA; vim-scripts-xmledit <a href="http://identi.ca/api/magthe/statuses/44833997" class="aktt_tweet_time">#</a></li>
    <li>Surely it&#039;s a bit silly that the username counts in replies! <a href="http://identi.ca/api/magthe/statuses/44886732" class="aktt_tweet_time">#</a></li>
    <li>? @<a href="http://identi.ca/api/johnnieingram" class="aktt_username">johnnieingram</a>: I&#039;m trying to think how this could possibly be any cooler, but I&#039;m coming up blank <a href="http://youtu.be/PfK-UzQ48JE" rel="nofollow">http://youtu.be/PfK-UzQ48JE</a> <a href="http://identi.ca/api/magthe/statuses/44911919" class="aktt_tweet_time">#</a></li>
    <li>List changesets touching a set of files #<a href="http://search.identi.ca/api/search.json?q=%23hg" class="aktt_hashtag">hg</a>  for f in *.c; do hg log -f $f|grep changeset|cut -f2,3 -d:|tr -d &#039; &#039;; done|sort|uniq <a href="http://identi.ca/api/magthe/statuses/44912429" class="aktt_tweet_time">#</a></li>
    <li>Wanted: a #<a href="http://search.identi.ca/api/search.json?q=%23wp" class="aktt_hashtag">wp</a> plugin that links a blog post to its reddit page (if there is one). <a href="http://identi.ca/api/magthe/statuses/44949676" class="aktt_tweet_time">#</a></li>
    <li>Note to self: the only functioning #<a href="http://search.identi.ca/api/search.json?q=%23arch" class="aktt_hashtag">arch</a> package for rpm is rpm-org (off of #<a href="http://search.identi.ca/api/search.json?q=%23aur" class="aktt_hashtag">aur</a> of course). <a href="http://identi.ca/api/magthe/statuses/45013541" class="aktt_tweet_time">#</a></li>
    <li>I&#039;m still not quite back to normal after the £566 car &quot;service&quot; yesterday <img src='http://therning.org/magnus/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' />  <a href="http://identi.ca/api/magthe/statuses/45098780" class="aktt_tweet_time">#</a></li>
    <li>Seriously considering moving my CMake/OCaml stuff off of bitbucket, git+branches is just better than HG+patchqueues. <a href="http://identi.ca/api/magthe/statuses/45154527" class="aktt_tweet_time">#</a></li>
    <li>So, now cmake-ocaml lives on github instead. <a href="http://identi.ca/api/magthe/statuses/45187887" class="aktt_tweet_time">#</a></li>
    <li>Hacking a bit more on cmake-ocaml; adding simple annot support, not sure what I&#039;m doing though, so likely to not be what people want <img src='http://therning.org/magnus/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  <a href="http://identi.ca/api/magthe/statuses/45282435" class="aktt_tweet_time">#</a></li>
    <li>Many Americans seem to confuse &quot;loud minority&quot; with &quot;majority&quot;. <a href="http://identi.ca/api/magthe/statuses/45287571" class="aktt_tweet_time">#</a></li>
    <li>Funny: <a href="http://feeds.wired.com/~r/wired27b/~3/IEM0MNEAkaU/" rel="nofollow">http://feeds.wired.com/~r/wired27b/~3/IEM0MNEAkaU/</a> <a href="http://identi.ca/api/magthe/statuses/45287674" class="aktt_tweet_time">#</a></li>
    <li>I couldn&#039;t agree more: <a href="http://www.thelocal.se/28198/20100805/" rel="nofollow">http://www.thelocal.se/28198/20100805/</a> <a href="http://identi.ca/api/magthe/statuses/45287739" class="aktt_tweet_time">#</a></li>
    <li>Yay, after recent kernel upgrade hibernate+suspend is now working properly. #<a href="http://search.identi.ca/api/search.json?q=%23arch" class="aktt_hashtag">arch</a> #linux <a href="http://identi.ca/api/magthe/statuses/45334579" class="aktt_tweet_time">#</a></li>
</ul>

<p class="aktt_credit">Powered by <a href="http://alexking.org/projects/wordpress">Twitter Tools</a></p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Bookmark</a> </p>]]></content:encoded>
			<wfw:commentRss>http://therning.org/magnus/archives/863/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dent Weekly Updates for 2010-08-01</title>
		<link>http://therning.org/magnus/archives/845</link>
		<comments>http://therning.org/magnus/archives/845#comments</comments>
		<pubDate>Sun, 01 Aug 2010 21:59:00 +0000</pubDate>
		<dc:creator>Magnus</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[dents]]></category>

		<guid isPermaLink="false">http://therning.org/magnus/archives/845</guid>
		<description><![CDATA[Finally I&#039;ve upgraded #wordpress on therning.org/magnus # Powered by Twitter Tools]]></description>
			<content:encoded><![CDATA[<ul class="aktt_tweet_digest">
    <li>Finally I&#039;ve upgraded #<a href="http://search.identi.ca/api/search.json?q=%23wordpress" class="aktt_hashtag">wordpress</a> on therning.org/magnus <a href="http://identi.ca/api/magthe/statuses/44444012" class="aktt_tweet_time">#</a></li>
</ul>

<p class="aktt_credit">Powered by <a href="http://alexking.org/projects/wordpress">Twitter Tools</a></p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Bookmark</a> </p>]]></content:encoded>
			<wfw:commentRss>http://therning.org/magnus/archives/845/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Any Haskell puzzlers?</title>
		<link>http://therning.org/magnus/archives/835</link>
		<comments>http://therning.org/magnus/archives/835#comments</comments>
		<pubDate>Sun, 01 Aug 2010 17:24:32 +0000</pubDate>
		<dc:creator>Magnus</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[puzzler]]></category>

		<guid isPermaLink="false">http://therning.org/magnus/?p=835</guid>
		<description><![CDATA[I just watched Joshua Block&#8217;s talk Effective Java &#8211; Still Effective After All These Years. I&#8217;m not a Java developeri but I still found the talk very interesting. Mr Block offers tips and tricks to deal effectively with a few aspects of Java, and I&#8217;m sure many a Java developer out there would find that [...]]]></description>
			<content:encoded><![CDATA[<p>I just watched Joshua Block&#8217;s talk <a href="http://www.youtube.com/watch?v=V1vQf4qyMXg">Effective Java &#8211; Still Effective After All These Years</a>.  I&#8217;m not a Java developer<sup><a href="http://therning.org/magnus/archives/835#footnote_0_835" id="identifier_0_835" class="footnote-link footnote-identifier-link" title="If I ever find myself in a situation that calls for Java I&amp;#8217;m very likely to spend some time looking at Scala   ">i</a></sup> but I still found the talk very interesting.  Mr Block offers tips and tricks to deal effectively with a few aspects of Java, and I&#8217;m sure many a Java developer out there would find that part very interesting.  For me however, the most interesting part was the appetizers and the dessert <img src='http://therning.org/magnus/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>

<p>The appetizer and dessert consisted of three puzzlers.  A puzzler is a piece of code that high-lights some peculiarity of the language or standard libraries.  The puzzlers in this talk were are follows:</p>

<h3>Simple question</h3>

<p>What is printed by the following code, and why?</p>


<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> SimpleQuestion <span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">boolean</span> yesOrNo<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> s<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    s <span style="color: #339933;">=</span> s.<span style="color: #006633;">toLowerCase</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>s.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;yes&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> s.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;t&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> s.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;y&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
      s <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;true&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #003399;">Boolean</span>.<span style="color: #006633;">getBoolean</span><span style="color: #009900;">&#40;</span>s<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>yesOrNo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;true&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; &quot;</span> <span style="color: #339933;">+</span> yesOrNo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;YeS&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>


<h3>Searching</h3>

<p>What is the result of the following code, and why?</p>


<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.*</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Searching <span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> strs <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> <span style="color: #0000ff;">&quot;0&quot;</span>, <span style="color: #0000ff;">&quot;1&quot;</span>, <span style="color: #0000ff;">&quot;2&quot;</span>, <span style="color: #0000ff;">&quot;3&quot;</span>, <span style="color: #0000ff;">&quot;4&quot;</span>, <span style="color: #0000ff;">&quot;5&quot;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Translate string array into list of integer</span>
    List<span style="color: #339933;">&lt;</span>Integer<span style="color: #339933;">&gt;</span> ints <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ArrayList<span style="color: #339933;">&lt;</span>Integer<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> s <span style="color: #339933;">:</span> strs<span style="color: #009900;">&#41;</span>
      ints.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Integer</span>.<span style="color: #006633;">valueOf</span><span style="color: #009900;">&#40;</span>s<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Collections</span>.<span style="color: #006633;">binarySearch</span><span style="color: #009900;">&#40;</span>ints, <span style="color: #cc66cc;">1</span>, cmp<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">static</span> Comparator<span style="color: #339933;">&lt;</span>Integer<span style="color: #339933;">&gt;</span> cmp <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Comparator<span style="color: #339933;">&lt;</span>Integer<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> compare<span style="color: #009900;">&#40;</span><span style="color: #003399;">Integer</span> i, <span style="color: #003399;">Integer</span> j<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">return</span> i <span style="color: #339933;">&lt;</span> j <span style="color: #339933;">?</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span> <span style="color: #339933;">:</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">==</span> j <span style="color: #339933;">?</span> <span style="color: #cc66cc;">0</span> <span style="color: #339933;">:</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>


<h3>PrintWords</h3>

<p>This one consists of two classes, which are compiled together:</p>


<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> PrintWords <span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>Words.<span style="color: #006633;">FIRST</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; &quot;</span> <span style="color: #339933;">+</span> Words.<span style="color: #006633;">SECOND</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; &quot;</span> <span style="color: #339933;">+</span> Words.<span style="color: #006633;">THIRD</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>



<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Words <span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> FIRST <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;the&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> SECOND <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> THIRD <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;set&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>


<p>Now modify the latter like this:</p>


<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Words <span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> FIRST <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;physics&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> SECOND <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;chemistry&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> THIRD <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;biology&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>


<p>Compile the second version of <code>Words.java</code> alone and then run <code>PrintWords</code>, what is the result and why?</p>

<h3>Any puzzlers for Haskell?</h3>

<p>Of course I couldn&#8217;t help but wonder what puzzlers there are for Haskell.  Do note though that puzzlers aren&#8217;t just obfuscated code; they are readable code that you think does one thing but in reality it does something else.  I&#8217;d really like to read any Haskell puzzlers you can come up with.  Post them on your own blogs, or as comments to this post.</p>

<p><strong>NB</strong> I should probably mention that I <em>really</em> don&#8217;t want answers to the puzzlers.  I&#8217;ve watched Josh Bloch&#8217;s presentation, and I think anyone interested in finding out should watch it for themselves.</p>
<ol class="footnotes"><li id="footnote_0_835" class="footnote">If I ever find myself in a situation that calls for Java I&#8217;m very likely to spend some time looking at Scala <img src='http://therning.org/magnus/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  </li></ol><p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Bookmark</a> </p>]]></content:encoded>
			<wfw:commentRss>http://therning.org/magnus/archives/835/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Modifying Twitter Tools (WordPress plugin) for use with identi.ca</title>
		<link>http://therning.org/magnus/archives/825</link>
		<comments>http://therning.org/magnus/archives/825#comments</comments>
		<pubDate>Fri, 30 Jul 2010 09:36:55 +0000</pubDate>
		<dc:creator>Magnus</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[identi.ca]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://therning.org/magnus/?p=825</guid>
		<description><![CDATA[This is almost silly, so I&#8217;ll be surprised if it works flawlessly, so far though it seems to work well enough. I got Twitter Tools to work with identi.ca by modifying the file twitter-tools.php so that the URIs used are: define&#40;'AKTT_API_POST_STATUS', 'http://identi.ca/api/statuses/update.json'&#41;; define&#40;'AKTT_API_USER_TIMELINE', 'http://identi.ca/api/statuses/user_timeline.json'&#41;; define&#40;'AKTT_API_STATUS_SHOW', 'http://identi.ca/api/statuses/show/###ID###.json'&#41;; define&#40;'AKTT_PROFILE_URL', 'http://identi.ca/api/###USERNAME###'&#41;; define&#40;'AKTT_STATUS_URL', 'http://identi.ca/api/###USERNAME###/statuses/###STATUS###'&#41;; define&#40;'AKTT_HASHTAG_URL', 'http://search.identi.ca/api/search.json?q=###HASHTAG###'&#41;; Hopefully this is [...]]]></description>
			<content:encoded><![CDATA[<p>This is almost silly, so I&#8217;ll be surprised if it works flawlessly, so far though it seems to work well enough. <img src='http://therning.org/magnus/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>

<p>I got <a href="http://wordpress.org/extend/plugins/twitter-tools/">Twitter Tools</a> to work with <a href="http://www.identi.ca/">identi.ca</a> by modifying the file <code>twitter-tools.php</code> so that the URIs used are:</p>


<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'AKTT_API_POST_STATUS'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'http://identi.ca/api/statuses/update.json'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'AKTT_API_USER_TIMELINE'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'http://identi.ca/api/statuses/user_timeline.json'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'AKTT_API_STATUS_SHOW'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'http://identi.ca/api/statuses/show/###ID###.json'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'AKTT_PROFILE_URL'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'http://identi.ca/api/###USERNAME###'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'AKTT_STATUS_URL'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'http://identi.ca/api/###USERNAME###/statuses/###STATUS###'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'AKTT_HASHTAG_URL'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'http://search.identi.ca/api/search.json?q=###HASHTAG###'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>


<p>Hopefully this is all that&#8217;s needed <img src='http://therning.org/magnus/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Bookmark</a> </p>]]></content:encoded>
			<wfw:commentRss>http://therning.org/magnus/archives/825/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Validating names in SSL certificates using OpenSSL (0.9.8)</title>
		<link>http://therning.org/magnus/archives/812</link>
		<comments>http://therning.org/magnus/archives/812#comments</comments>
		<pubDate>Wed, 17 Mar 2010 00:38:17 +0000</pubDate>
		<dc:creator>Magnus</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[openssl]]></category>

		<guid isPermaLink="false">http://therning.org/magnus/?p=812</guid>
		<description><![CDATA[Recently I&#8217;ve battled with OpenSSL at work. One thing I needed to do was add name validation to a program that previously hasn&#8217;t had it. In an attempt to avoid obvious mistakes I went looking for existing examples for how to do it. I came across some code from Secure Programming.com, it can be found [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I&#8217;ve battled with <a href="http://openssl.org/">OpenSSL</a> at work.  One thing I needed to do was add name validation to a program that previously hasn&#8217;t had it.  In an attempt to avoid obvious mistakes I went looking for existing examples for how to do it.  I came across some code from <a href="http://secureprogramming.com/">Secure Programming.com</a>, it can be found in the <a href="http://secureprogramming.com/downloads/spc-1.1.tar.gz">code from the book</a> in &#8220;/spc-1.1/chapter10/8-unix.c&#8221;.  Just too bad only a part of the code actually works as advertised.  On top of that the working part uses old functions which remain in the API only for backwards compatibility.</p>

<p>In trying to fix up that code I wrote the following little example code for extracting CN and subjectAltName:</p>


<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include &lt;stdlib.h&gt;</span>
<span style="color: #339933;">#include &lt;stdio.h&gt;</span>
&nbsp;
<span style="color: #339933;">#include &lt;openssl/pem.h&gt;</span>
<span style="color: #339933;">#include &lt;openssl/x509v3.h&gt;</span>
&nbsp;
<span style="color: #993333;">void</span> getCN<span style="color: #009900;">&#40;</span> X509 <span style="color: #339933;">*</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #993333;">void</span> getSubjectAltName<span style="color: #009900;">&#40;</span> X509 <span style="color: #339933;">*</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">int</span>
main<span style="color: #009900;">&#40;</span> <span style="color: #993333;">int</span> argc<span style="color: #339933;">,</span> <span style="color: #993333;">char</span> <span style="color: #339933;">**</span>argv <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    FILE <span style="color: #339933;">*</span>fpem<span style="color: #339933;">;</span>
    X509 <span style="color: #339933;">*</span>cert<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><span style="color: #009900;">&#40;</span> fpem <span style="color: #339933;">=</span> fopen<span style="color: #009900;">&#40;</span> argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;r&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        fprintf<span style="color: #009900;">&#40;</span> stderr<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;Couldn't open the PEM file: %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span><span style="color: #009900;">&#40;</span> EXIT_FAILURE <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><span style="color: #009900;">&#40;</span> cert <span style="color: #339933;">=</span> PEM_read_X509<span style="color: #009900;">&#40;</span> fpem<span style="color: #339933;">,</span> NULL<span style="color: #339933;">,</span> NULL<span style="color: #339933;">,</span> NULL <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        fclose<span style="color: #009900;">&#40;</span> fpem <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        fprintf<span style="color: #009900;">&#40;</span> stderr<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;Failed to read the PEM file: %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span><span style="color: #009900;">&#40;</span> EXIT_FAILURE <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    getCN<span style="color: #009900;">&#40;</span> cert <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    getSubjectAltName<span style="color: #009900;">&#40;</span> cert <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    fclose<span style="color: #009900;">&#40;</span> fpem <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span><span style="color: #009900;">&#40;</span> EXIT_SUCCESS <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">void</span>
getCN<span style="color: #009900;">&#40;</span> X509 <span style="color: #339933;">*</span>cert <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span> <span style="color: #ff0000;">&quot;## %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> __PRETTY_FUNCTION__ <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    X509_NAME <span style="color: #339933;">*</span>subjName<span style="color: #339933;">;</span>
    <span style="color: #993333;">int</span> idx<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><span style="color: #009900;">&#40;</span> subjName <span style="color: #339933;">=</span> X509_get_subject_name<span style="color: #009900;">&#40;</span> cert <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
        fprintf<span style="color: #009900;">&#40;</span> stderr<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;X509_get_subject_name failed&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    idx <span style="color: #339933;">=</span> X509_NAME_get_index_by_NID<span style="color: #009900;">&#40;</span> subjName<span style="color: #339933;">,</span> NID_commonName<span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    X509_NAME_ENTRY <span style="color: #339933;">*</span>entry <span style="color: #339933;">=</span> X509_NAME_get_entry<span style="color: #009900;">&#40;</span> subjName<span style="color: #339933;">,</span> idx <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    ASN1_STRING <span style="color: #339933;">*</span>entryData <span style="color: #339933;">=</span> X509_NAME_ENTRY_get_data<span style="color: #009900;">&#40;</span> entry <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>utf8<span style="color: #339933;">;</span>
    <span style="color: #993333;">int</span> length <span style="color: #339933;">=</span> ASN1_STRING_to_UTF8<span style="color: #009900;">&#40;</span> <span style="color: #339933;">&amp;</span>utf8<span style="color: #339933;">,</span> entryData <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span> <span style="color: #ff0000;">&quot;CN value: %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> utf8 <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span> <span style="color: #ff0000;">&quot;CN length: %d<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> length <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    OPENSSL_free<span style="color: #009900;">&#40;</span> utf8 <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">void</span> getSubjectAltName<span style="color: #009900;">&#40;</span> X509 <span style="color: #339933;">*</span>cert <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span> <span style="color: #ff0000;">&quot;## %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> __PRETTY_FUNCTION__ <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    GENERAL_NAMES <span style="color: #339933;">*</span>sANs<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><span style="color: #009900;">&#40;</span> sANs <span style="color: #339933;">=</span> X509_get_ext_d2i<span style="color: #009900;">&#40;</span> cert<span style="color: #339933;">,</span> NID_subject_alt_name<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span> <span style="color: #ff0000;">&quot;No subjectAltName extension<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #993333;">int</span> i<span style="color: #339933;">,</span> numAN <span style="color: #339933;">=</span> sk_GENERAL_NAME_num<span style="color: #009900;">&#40;</span> sANs <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span> <span style="color: #ff0000;">&quot;subjectAltName entries: %d<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> numAN <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span> i <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> numAN<span style="color: #339933;">;</span> <span style="color: #339933;">++</span>i <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        GENERAL_NAME <span style="color: #339933;">*</span>sAN <span style="color: #339933;">=</span> sk_GENERAL_NAME_value<span style="color: #009900;">&#40;</span> sANs<span style="color: #339933;">,</span> i <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">// we only care about DNS entries</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> GEN_DNS <span style="color: #339933;">==</span> sAN<span style="color: #339933;">-&gt;</span>type <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>dns<span style="color: #339933;">;</span>
            ASN1_STRING_to_UTF8<span style="color: #009900;">&#40;</span> <span style="color: #339933;">&amp;</span>dns<span style="color: #339933;">,</span> sAN<span style="color: #339933;">-&gt;</span>d.<span style="color: #202020;">dNSName</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span> <span style="color: #ff0000;">&quot;subjectAltName DNS: %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> dns <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            OPENSSL_free<span style="color: #009900;">&#40;</span> dns <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>


<p>Based on this I should be able to finish the patch I&#8217;ve been working on.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Bookmark</a> </p>]]></content:encoded>
			<wfw:commentRss>http://therning.org/magnus/archives/812/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My new browser setup at work</title>
		<link>http://therning.org/magnus/archives/804</link>
		<comments>http://therning.org/magnus/archives/804#comments</comments>
		<pubDate>Thu, 11 Feb 2010 23:11:28 +0000</pubDate>
		<dc:creator>Magnus</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[dropbox]]></category>
		<category><![CDATA[firefox]]></category>

		<guid isPermaLink="false">http://therning.org/magnus/?p=804</guid>
		<description><![CDATA[I am very keen on keeping my private and work information separate. E.g. I would never read my personal and work email in the same MUA, instead I read work email in Thunderbird and the few times I read private email during working hours I do that using the web interface to GMail. At home [...]]]></description>
			<content:encoded><![CDATA[<p>I am very keen on keeping my private and work information separate.  E.g. I
would never read my personal and work email in the same MUA, instead I read
work email in Thunderbird and the few times I read private email during working
hours I do that using the web interface to GMail.  At home it&#8217;s the other way
around, Thunderbird for personal email, and a web interface to read work email.
I used to have a similar setup for my browsing to keep bookmarks and saved
passwords for the different areas of my life separate.  Firefox was my work
browser and Epiphany was my personal browser.</p>

<p>With the recent move to use webkit I noticed that there are a few bits with
Epiphany that really bugs me though.  Especially its inability to remember
passwords; on my Eee it&#8217;s just a killer to not be able to do that.  So, I
decided to take a look at Firefox again, especially to see whether there are any
add-ons that would help.  And there are.  These are the add-ons I found useful for this:</p>

<h3>Profile Manager and Synchronizer</h3>

<p>The most important piece of the setup is the addon <a href="https://addons.mozilla.org/en-US/firefox/addon/9452">Profile Manager and Synchronizer</a>.  It make sit easy to have more than one instance of Firefox running at the same time, with different profiles active in each one.</p>

<p>At first I tried synchronising profiles via <a href="http://www.dropbox.com">dropbox</a>, but that resulted in <em>a lot</em> of updates each time so I quickly stopped.  I can recommend using it once though, to get the profiles to all the computers in the first place.</p>

<p>The plugin author says there will be a version that works with 3.6 soon.  In the meantime I can report that I&#8217;ve had no issues with manually modifying the version range just to get it to install.</p>

<h3>Xmarks</h3>

<p>Since I don&#8217;t synchronise my profiles I do need to synchronise my bookmarks, and for that I use <a href="https://addons.mozilla.org/en-US/firefox/addon/2410">Xmarks</a>.</p>

<h3>Diigo</h3>

<p><a href="http://www.diigo.com/">Diigo</a> is a social bookmarking site.  There seems to be about 13 to a dozen of those, but there are a couple of things that make Diigo different.</p>

<p>With the plugin I can easily store away pages for reading at some later date.  In the past I&#8217;ve had a bookmark folder, or slightly more recently a tag, that I used to mark up pages that I&#8217;d like to take a closer look at.  I&#8217;ve stopped that completely, and now I just mark pages as <em>unread</em> in Diigo.  Just another way of reducing the clutter among my bookmarks.</p>

<p>The probably coolest feature is commenting on webpages.  I mostly use that to add private comments to web pages, e.g. when I do some research into some topic (so far it&#8217;s mostly been for items I&#8217;m considering buying), but it&#8217;s also possible to make public comments.  I&#8217;ve found it useful on more than one occasion to have a quick look through the public comments other people have put on pages.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Bookmark</a> </p>]]></content:encoded>
			<wfw:commentRss>http://therning.org/magnus/archives/804/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Good online stores for yoga equipment</title>
		<link>http://therning.org/magnus/archives/800</link>
		<comments>http://therning.org/magnus/archives/800#comments</comments>
		<pubDate>Wed, 10 Feb 2010 23:25:44 +0000</pubDate>
		<dc:creator>Magnus</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[natural rubber]]></category>
		<category><![CDATA[prana]]></category>
		<category><![CDATA[yoga]]></category>
		<category><![CDATA[yoga mat]]></category>

		<guid isPermaLink="false">http://therning.org/magnus/?p=800</guid>
		<description><![CDATA[The condensed version: I&#8217;ve found both YogaStudio and Yoga United to be excellent online stores for yoga equipment. Longer version About a month ago I decided to finally invest in a yoga mat. After a bit of research I found the prAna Revolution, it&#8217;s an extra wide, extra long mat made of natural rubber. I [...]]]></description>
			<content:encoded><![CDATA[<p>The condensed version: I&#8217;ve found both <a href="http://www.yogastudio.co.uk/">YogaStudio</a> and <a href="http://yogaunited.co.uk/">Yoga United</a> to be excellent online stores for yoga equipment.</p>

<h3>Longer version</h3>

<p>About a month ago I decided to finally invest in a yoga mat.  After a bit of research I found the <a href="http://www.prana.com/002976-Revolution-Natural-Sticky-Mat.aspx">prAna Revolution</a>, it&#8217;s an extra wide, extra long mat made of natural rubber.  I decided to order it from <a href="http://www.yogastudio.co.uk/">YogaStudio</a>.  It was completely eventless and slightly quicker than I expected.  So two big thumbs up for YogaStudio.</p>

<p>After receiving the mat I realised I really would need a bag for it.  I found it very difficult to find a bag that would fit my slightly over-sized mat.  Finally I stumbled on <a href="http://yogaunited.co.uk/">Yoga United</a>, who had a good price on an <a href="http://yogaunited.co.uk/prod5.asp?ID=142&amp;offset=&amp;prod_id=1765&amp;grpid=1765&amp;#prod_anchor">extra long bag made out of cotton</a>.  They also delivered quicker than expected, unfortunately they didn&#8217;t ship the one I actually ordered.  What I got was the smaller size bag, too small for my mat, but it fit my wife&#8217;s mat perfectly and she wanted to keep it.  Instead of the hazzle of sending it back I agreed with the lady at Yoga United that it would be simpler for them to just let me order another extra long bag and let me keep the one I had.  The second bag arrived the next day.  Again brilliant service.</p>

<p>Finally, I can really recommend the mat I bought.  Yes, it&#8217;s pricy, but so far I&#8217;ve found it to be brilliant.  The bag, you ask.  Well, the mat doesn&#8217;t really <em>want</em> to stay rolled up, if I put it that way.  Also, cotton isn&#8217;t a material that natural rubber slides easily on.  It isn&#8217;t <em>that</em> hard to get the mat into the bag, but it helps to be patient <img src='http://therning.org/magnus/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Bookmark</a> </p>]]></content:encoded>
			<wfw:commentRss>http://therning.org/magnus/archives/800/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Gnome: 2 questions that go unanswered</title>
		<link>http://therning.org/magnus/archives/795</link>
		<comments>http://therning.org/magnus/archives/795#comments</comments>
		<pubDate>Fri, 27 Nov 2009 17:25:26 +0000</pubDate>
		<dc:creator>Magnus</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[dropbox]]></category>
		<category><![CDATA[gnome]]></category>
		<category><![CDATA[network_manager]]></category>

		<guid isPermaLink="false">http://therning.org/magnus/?p=795</guid>
		<description><![CDATA[Since no one on the Gnome mailing list seems to be able to answer these questions I thought I&#8217;d try some other venues for getting them answered. The audience for my blog isn&#8217;t that big, but just maybe there&#8217;s someone out there who knows the answers to these questions related to Gnome configuration. Mail one [...]]]></description>
			<content:encoded><![CDATA[<p>Since no one on the Gnome mailing list seems to be able to answer these questions I thought I&#8217;d try some other venues for getting them answered.  The audience for my blog isn&#8217;t that big, but just maybe there&#8217;s someone out there who knows the answers to these questions related to Gnome configuration.  <a href="http://mail.gnome.org/archives/gnome-list/2009-November/msg00011.html">Mail one</a> and <a href="http://mail.gnome.org/archives/gnome-list/2009-November/msg00012.html">mail two</a>.</p>

<h3>1: Running GUI tool after NM has brought up network</h3>

<p>I run <a href="http://www.dropbox.com/">dropbox</a> on my laptop, but their software is crap at handling that the network comes up only after the dropbox service has started<sup><a href="http://therning.org/magnus/archives/795#footnote_0_795" id="identifier_0_795" class="footnote-link footnote-identifier-link" title="I&amp;#8217;ve noticed no problem when network goes away and then comes back, dropbox picks that up just fine.  But if the network isn&amp;#8217;t there to start with, that it can&amp;#8217;t handle.  I&amp;#8217;m somehow at a loss how to write a program that handles the former but not the latter.   ">i</a></sup></p>

<p>I know of the possibility of dropping a file in <code>/etc/NetworkManager/dispatcher.d/</code>, but that doesn&#8217;t work in this case since I need the program to run &#8220;in my desktop&#8221;.  Well, at least I haven&#8217;t managed to get the dropbox server to throw up an icon in my Gnome tool bar like it should, unless I run it from inside the desktop environment.</p>

<p>Any suggestions on how to solve this problem?</p>

<h3>2: Changing background of the Gnome screensaver</h3>

<p>I think Gnome comes with quite possibly the ugliest background for a screensaver I&#8217;ve ever seen.  It&#8217;s a close-up on a green leaf or something.  Absolutely hideous.  I want to change it.  To something nice, like a solid black.  Actually just about anything else would do.  But how?</p>

<p>GDM came with the same ugly background.  Luckily I managed to find <a href="http://wiki.archlinux.org/index.php/GNOME#Configure">instructions on the Arch wiki to change GDM background</a>.  I&#8217;ve tried and failed to use a similar trick on the screensaver.</p>

<p>Please, help me escape the ugly background of the Gnome screensaver!</p>
<ol class="footnotes"><li id="footnote_0_795" class="footnote">I&#8217;ve noticed no problem when network goes away and then comes back, dropbox picks that up just fine.  But if the network isn&#8217;t there to start with, that it can&#8217;t handle.  I&#8217;m somehow at a loss how to write a program that handles the former <em>but not the latter</em>. <img src='http://therning.org/magnus/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  </li></ol><p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Bookmark</a> </p>]]></content:encoded>
			<wfw:commentRss>http://therning.org/magnus/archives/795/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Bash is simply insane</title>
		<link>http://therning.org/magnus/archives/783</link>
		<comments>http://therning.org/magnus/archives/783#comments</comments>
		<pubDate>Thu, 05 Nov 2009 10:31:58 +0000</pubDate>
		<dc:creator>Magnus</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[scoping]]></category>

		<guid isPermaLink="false">http://therning.org/magnus/?p=783</guid>
		<description><![CDATA[What do you think the following scripti will print? foo&#40;&#41; &#123; true &#124; while true; do false rc=$? if &#91; $rc -eq 1 &#93;; then return 1 fi done echo $? return 0 &#125; &#160; foo &#124;&#124; echo &#34;Failed foo&#34; Run it and see. I suspect everyone but the script gurus out there will be [...]]]></description>
			<content:encoded><![CDATA[<p>What do you think the following script<sup><a href="http://therning.org/magnus/archives/783#footnote_0_783" id="identifier_0_783" class="footnote-link footnote-identifier-link" title="The script is somewhat artificial, who would ever use the construct true | while ...?  I&amp;#8217;ve used this just to show the point while keeping the examples short.  Feel free to replace that part with something more useful, like cat myfile | while read ....">i</a></sup> will print?</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">foo<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #c20cb9; font-weight: bold;">true</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #c20cb9; font-weight: bold;">true</span>; <span style="color: #000000; font-weight: bold;">do</span>
        <span style="color: #c20cb9; font-weight: bold;">false</span>
        <span style="color: #007800;">rc</span>=<span style="color: #007800;">$?</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$rc</span> <span style="color: #660033;">-eq</span> <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
            <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">1</span>
        <span style="color: #000000; font-weight: bold;">fi</span>
    <span style="color: #000000; font-weight: bold;">done</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$?</span>
    <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">0</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
foo <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Failed foo&quot;</span></pre></div></div>


<p>Run it and see.  I suspect everyone but the script gurus out there will be surprised.</p>

<p>What about this script then?</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">bar <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #7a0874; font-weight: bold;">local</span> <span style="color: #007800;">rc</span>=<span style="color: #000000;">0</span>
    <span style="color: #c20cb9; font-weight: bold;">true</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #c20cb9; font-weight: bold;">true</span>; <span style="color: #000000; font-weight: bold;">do</span>
        <span style="color: #c20cb9; font-weight: bold;">false</span>
        <span style="color: #007800;">rc</span>=<span style="color: #007800;">$?</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$rc</span> <span style="color: #660033;">-eq</span> <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
            <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">1</span>
        <span style="color: #000000; font-weight: bold;">fi</span>
    <span style="color: #000000; font-weight: bold;">done</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$?</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$rc</span>
    <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">0</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
bar</pre></div></div>


<p>Surprised again?</p>

<p>I guess this means that scoping in bash is somewhat more complicated then I would have ever guessed.</p>
<ol class="footnotes"><li id="footnote_0_783" class="footnote">The script is somewhat artificial, who would ever use the construct <code>true | while ...</code>?  I&#8217;ve used this just to show the point while keeping the examples short.  Feel free to replace that part with something more useful, like <code>cat myfile | while read ...</code>.</li></ol><p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Bookmark</a> </p>]]></content:encoded>
			<wfw:commentRss>http://therning.org/magnus/archives/783/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Playing with sockets in Haskell</title>
		<link>http://therning.org/magnus/archives/778</link>
		<comments>http://therning.org/magnus/archives/778#comments</comments>
		<pubDate>Fri, 30 Oct 2009 21:27:21 +0000</pubDate>
		<dc:creator>Magnus</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[fork]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[socket]]></category>

		<guid isPermaLink="false">http://therning.org/magnus/?p=778</guid>
		<description><![CDATA[This is another one of those posts that I make mostly for myself, you know for organising and help my memory There are as far as I can see three ways to deal with sockets in Haskell. There&#8217;s the type Socket which is used throughout Network.Socket. From that it&#8217;s possible to get to the underlying [...]]]></description>
			<content:encoded><![CDATA[<p>This is another one of those posts that I make mostly for myself, you know for
organising and help my memory <img src='http://therning.org/magnus/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>

<p>There are as far as I can see three ways to deal with sockets in Haskell.
There&#8217;s the type <code>Socket</code> which is used throughout <code>Network.Socket</code>.  From
that it&#8217;s possible to get to the underlying filedescriptor, and it in turn can
be converted to a <code>Handle</code>.</p>

<p>When coupled with fork+exec it&#8217;s crucial to make sure the child process can
find the socket  Leaving it in a predictable place seems to be the easiest way
to do that, and as far as I can see that requires using <code>dupTo</code> from
<code>System.Posix.IO</code>.  So, on the child-side it&#8217;s necessary to find a way to turn
an integer (<code>CInt</code>) into something that can be treated as a socket (i.e. a
<code>Socket</code>, a <code>Handle</code>, or a filedescriptor).</p>

<p>A basic parent-child which obviously won&#8217;t work since the child&#8217;s socket is
represented as a <code>Socket</code>:</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">import</span> Control<span style="color: #339933; font-weight: bold;">.</span>Concurrent
<span style="color: #06c; font-weight: bold;">import</span> System<span style="color: #339933; font-weight: bold;">.</span>Posix<span style="color: #339933; font-weight: bold;">.</span>Process
<span style="color: #06c; font-weight: bold;">import</span> Network<span style="color: #339933; font-weight: bold;">.</span>Socket
&nbsp;
childFunc s <span style="color: #339933; font-weight: bold;">=</span> send s <span style="background-color: #3cb371;">&quot;Ping from child&quot;</span> <span style="color: #339933; font-weight: bold;">&gt;&gt;</span> <span style="font-weight: bold;">return</span> <span style="color: green;">&#40;</span><span style="color: green;">&#41;</span>
&nbsp;
main <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">do</span>
    <span style="color: green;">&#40;</span>childSock<span style="color: #339933; font-weight: bold;">,</span> parentSock<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">&lt;-</span> socketPair AF<span style="color: #339933; font-weight: bold;">_</span>UNIX Stream defaultProtocol
    <span style="font-weight: bold;">print</span> <span style="color: green;">&#40;</span>childSock<span style="color: #339933; font-weight: bold;">,</span> parentSock<span style="color: green;">&#41;</span>
    child <span style="color: #339933; font-weight: bold;">&lt;-</span> forkProcess <span style="color: #339933; font-weight: bold;">$</span> childFunc childSock
    recv parentSock <span style="color: red;">10</span> <span style="color: #339933; font-weight: bold;">&gt;&gt;=</span> <span style="font-weight: bold;">print</span></pre></div></div>


<p>Let the child take a <code>CInt</code> and turn it into a filedescriptor:</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">import</span> Control<span style="color: #339933; font-weight: bold;">.</span>Concurrent
<span style="color: #06c; font-weight: bold;">import</span> Control<span style="color: #339933; font-weight: bold;">.</span>Concurrent<span style="color: #339933; font-weight: bold;">.</span>MVar
<span style="color: #06c; font-weight: bold;">import</span> System<span style="color: #339933; font-weight: bold;">.</span>Posix<span style="color: #339933; font-weight: bold;">.</span>Process
<span style="color: #06c; font-weight: bold;">import</span> System<span style="color: #339933; font-weight: bold;">.</span>Posix<span style="color: #339933; font-weight: bold;">.</span><span style="color: #cccc00; font-weight: bold;">IO</span>
<span style="color: #06c; font-weight: bold;">import</span> System<span style="color: #339933; font-weight: bold;">.</span>Posix<span style="color: #339933; font-weight: bold;">.</span>Types
<span style="color: #06c; font-weight: bold;">import</span> Network<span style="color: #339933; font-weight: bold;">.</span>Socket
&nbsp;
childFunc sInt <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">do</span>
    <span style="color: #06c; font-weight: bold;">let</span> fd <span style="color: #339933; font-weight: bold;">=</span> Fd sInt
    fdWrite fd <span style="background-color: #3cb371;">&quot;Ping from child&quot;</span> <span style="color: #339933; font-weight: bold;">&gt;&gt;</span> <span style="font-weight: bold;">return</span> <span style="color: green;">&#40;</span><span style="color: green;">&#41;</span>
&nbsp;
main <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">do</span>
    <span style="color: green;">&#40;</span>childSock<span style="color: #339933; font-weight: bold;">,</span> parentSock<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">&lt;-</span> socketPair AF<span style="color: #339933; font-weight: bold;">_</span>UNIX Stream defaultProtocol
    <span style="color: #06c; font-weight: bold;">let</span> childInt <span style="color: #339933; font-weight: bold;">=</span> fdSocket childSock
    <span style="font-weight: bold;">print</span> <span style="color: green;">&#40;</span>childInt<span style="color: #339933; font-weight: bold;">,</span> parentSock<span style="color: green;">&#41;</span>
    child <span style="color: #339933; font-weight: bold;">&lt;-</span> forkProcess <span style="color: #339933; font-weight: bold;">$</span> childFunc childInt
    recv parentSock <span style="color: red;">10</span> <span style="color: #339933; font-weight: bold;">&gt;&gt;=</span> <span style="font-weight: bold;">print</span></pre></div></div>


<p>Let the child take a <code>CInt</code> and turn it into a <code>Handle</code>:</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">import</span> Control<span style="color: #339933; font-weight: bold;">.</span>Concurrent
<span style="color: #06c; font-weight: bold;">import</span> System<span style="color: #339933; font-weight: bold;">.</span>Posix<span style="color: #339933; font-weight: bold;">.</span>Process
<span style="color: #06c; font-weight: bold;">import</span> System<span style="color: #339933; font-weight: bold;">.</span>Posix<span style="color: #339933; font-weight: bold;">.</span><span style="color: #cccc00; font-weight: bold;">IO</span>
<span style="color: #06c; font-weight: bold;">import</span> System<span style="color: #339933; font-weight: bold;">.</span>Posix<span style="color: #339933; font-weight: bold;">.</span>Types
<span style="color: #06c; font-weight: bold;">import</span> Network<span style="color: #339933; font-weight: bold;">.</span>Socket
<span style="color: #06c; font-weight: bold;">import</span> System<span style="color: #339933; font-weight: bold;">.</span><span style="color: #cccc00; font-weight: bold;">IO</span>
&nbsp;
childFunc sInt <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">do</span>
    h <span style="color: #339933; font-weight: bold;">&lt;-</span> fdToHandle <span style="color: #339933; font-weight: bold;">$</span> Fd sInt
    hPutStr h <span style="background-color: #3cb371;">&quot;Ping from child&quot;</span>
    hFlush h
&nbsp;
main <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">do</span>
    <span style="color: green;">&#40;</span>childSock<span style="color: #339933; font-weight: bold;">,</span> parentSock<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">&lt;-</span> socketPair AF<span style="color: #339933; font-weight: bold;">_</span>UNIX Stream defaultProtocol
    <span style="color: #06c; font-weight: bold;">let</span> childInt <span style="color: #339933; font-weight: bold;">=</span> fdSocket childSock
    <span style="font-weight: bold;">print</span> <span style="color: green;">&#40;</span>childSock<span style="color: #339933; font-weight: bold;">,</span> parentSock<span style="color: green;">&#41;</span>
    child <span style="color: #339933; font-weight: bold;">&lt;-</span> forkProcess <span style="color: #339933; font-weight: bold;">$</span> childFunc childInt
    recv parentSock <span style="color: red;">10</span> <span style="color: #339933; font-weight: bold;">&gt;&gt;=</span> <span style="font-weight: bold;">print</span></pre></div></div>


<p>Let the child take a <code>CInt</code> and turn it into a <code>Socket</code><sup><a href="http://therning.org/magnus/archives/778#footnote_0_778" id="identifier_0_778" class="footnote-link footnote-identifier-link" title="It seems the socket
is in the Connected state after socketPair succeeds.">i</a></sup>:</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">import</span> Control<span style="color: #339933; font-weight: bold;">.</span>Concurrent
<span style="color: #06c; font-weight: bold;">import</span> Control<span style="color: #339933; font-weight: bold;">.</span>Concurrent<span style="color: #339933; font-weight: bold;">.</span>MVar
<span style="color: #06c; font-weight: bold;">import</span> System<span style="color: #339933; font-weight: bold;">.</span>Posix<span style="color: #339933; font-weight: bold;">.</span>Process
<span style="color: #06c; font-weight: bold;">import</span> System<span style="color: #339933; font-weight: bold;">.</span>Posix<span style="color: #339933; font-weight: bold;">.</span><span style="color: #cccc00; font-weight: bold;">IO</span>
<span style="color: #06c; font-weight: bold;">import</span> System<span style="color: #339933; font-weight: bold;">.</span>Posix<span style="color: #339933; font-weight: bold;">.</span>Types
<span style="color: #06c; font-weight: bold;">import</span> Network<span style="color: #339933; font-weight: bold;">.</span>Socket
&nbsp;
childFunc sInt <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">do</span>
    s <span style="color: #339933; font-weight: bold;">&lt;-</span> mkSocket sInt AF<span style="color: #339933; font-weight: bold;">_</span>UNIX Stream defaultProtocol Connected
    send s <span style="background-color: #3cb371;">&quot;Ping from child&quot;</span> <span style="color: #339933; font-weight: bold;">&gt;&gt;</span> <span style="font-weight: bold;">return</span> <span style="color: green;">&#40;</span><span style="color: green;">&#41;</span>
&nbsp;
main <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">do</span>
    <span style="color: green;">&#40;</span>childSock<span style="color: #339933; font-weight: bold;">,</span> parentSock<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">&lt;-</span> socketPair AF<span style="color: #339933; font-weight: bold;">_</span>UNIX Stream defaultProtocol
    <span style="color: #06c; font-weight: bold;">let</span> childInt <span style="color: #339933; font-weight: bold;">=</span> fdSocket childSock
    <span style="font-weight: bold;">print</span> <span style="color: green;">&#40;</span>childInt<span style="color: #339933; font-weight: bold;">,</span> parentSock<span style="color: green;">&#41;</span>
    child <span style="color: #339933; font-weight: bold;">&lt;-</span> forkProcess <span style="color: #339933; font-weight: bold;">$</span> childFunc childInt
    recv parentSock <span style="color: red;">10</span> <span style="color: #339933; font-weight: bold;">&gt;&gt;=</span> <span style="font-weight: bold;">print</span></pre></div></div>

<ol class="footnotes"><li id="footnote_0_778" class="footnote">It seems the socket
is in the <code>Connected</code> state after <code>socketPair</code> succeeds.</li></ol><p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Bookmark</a> </p>]]></content:encoded>
			<wfw:commentRss>http://therning.org/magnus/archives/778/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Dents for 2009-10-23</title>
		<link>http://therning.org/magnus/archives/775</link>
		<comments>http://therning.org/magnus/archives/775#comments</comments>
		<pubDate>Fri, 23 Oct 2009 22:59:59 +0000</pubDate>
		<dc:creator>Magnus</dc:creator>
				<category><![CDATA[Posts]]></category>

		<guid isPermaLink="false">http://therning.org/magnus/archives/775</guid>
		<description><![CDATA[How any serious project ever can choose git for version control is beyond me! # @shapr It&#8217;s available for pre-order already (£499), it should be available end of Oct I think. http://tinyurl.com/yhpyr3e # C++ is getting crazier and crazier: http://tinyurl.com/yk4nhz5 # Powered by modified Twitter Tools.]]></description>
			<content:encoded><![CDATA[<ul class="aktt_tweet_digest">
    <li>How any serious project ever can choose git for version control is beyond me! <a href="http://identi.ca/notice/5090570485">#</a></li>
    <li>@shapr It&#8217;s available for pre-order already (£499), it should be available end of Oct I think. <a href="http://tinyurl.com/yhpyr3e" rel="nofollow">http://tinyurl.com/yhpyr3e</a> <a href="http://identi.ca/notice/5090985733">#</a></li>
    <li>C++ is getting crazier and crazier: <a href="http://tinyurl.com/yk4nhz5" rel="nofollow">http://tinyurl.com/yk4nhz5</a> <a href="http://identi.ca/notice/5092236118">#</a></li>
</ul>

<p class="aktt_credit">Powered by modified <a href="http://alexking.org/projects/wordpress">Twitter Tools</a>.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Bookmark</a> </p>]]></content:encoded>
			<wfw:commentRss>http://therning.org/magnus/archives/775/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Epilicious is dead, say hello to BMS</title>
		<link>http://therning.org/magnus/archives/762</link>
		<comments>http://therning.org/magnus/archives/762#comments</comments>
		<pubDate>Fri, 23 Oct 2009 20:38:19 +0000</pubDate>
		<dc:creator>Magnus</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[epilicious]]></category>
		<category><![CDATA[epiphany]]></category>
		<category><![CDATA[seed]]></category>
		<category><![CDATA[vala]]></category>

		<guid isPermaLink="false">http://therning.org/magnus/?p=762</guid>
		<description><![CDATA[With Python being dropped as a language for extensions in epiphany 2.28 I needed to replace epilicious. I tried writing it in JavaScript (seed was integrated in 2.28), but I gave up due to hitting too many hurdles on the way. Instead I decided to rewrite epilicious using Vala and a minimal layer of C. [...]]]></description>
			<content:encoded><![CDATA[<p>With Python being dropped as a language for extensions in epiphany 2.28 I needed to replace <a href="http://therning.org/magnus/computer/epilicious">epilicious</a>.  I tried writing it in JavaScript (<a href="http://live.gnome.org/Seed">seed</a> was integrated in 2.28), but I gave up due to hitting too many hurdles on the way. Instead I decided to rewrite epilicious using <a href="http://live.gnome.org/Vala">Vala</a> and a minimal layer of C.</p>

<p>It turned out to be very doable, despite epiphany&#8217;s extension API lacking Vala bindings (Cosimo Cecchi, I&#8217;m looking at <a href="http://uwstopia.nl/blog/2008/07/vala-bindings-for-epiphany-extensions">you</a> <img src='http://therning.org/magnus/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  ).  Basically I did the following setup:</p>

<ol>
<li>Add the extension following the instructions in <a href="http://projects.gnome.org/epiphany/documentation/extensions/index.html">Writing Epiphany Extensions</a> by Adam Hooper.</li>
<li>Add a check for valac in <code>configure.ac</code>.</li>
<li>Add a rule in the extension&#8217;s <code>Makefile.am</code> to generate a C header file for all the Vala code, for use from C.</li>
</ol>

<p>Then I started writing the actual extension.  I did the minimal amount of work in C, trying to escape as soon as possible into Vala.  In the few places I needed to call from Vala into C I would declare a delegate in Vala, and pass a function from C<sup><a href="http://therning.org/magnus/archives/762#footnote_0_762" id="identifier_0_762" class="footnote-link footnote-identifier-link" title="The format of .vapi files are unknown to me, and I haven&amp;#8217;t managed to find much documentation.  Using function pointers seemed like an easier way, especially given that I needed this in exactly 3 places.">i</a></sup>.</p>

<p>I call this new version BMS, for <em>b</em>ook<em>m</em>ark <em>s</em>ynchronisation.  I have a <a href="http://therning.org/magnus_files/epiphany-extension-bms-1.0-2.src.tar.gz">patch for BMS that applies to epiphany 2.28.1</a>.  (The file also contain a <code>PKGBUILD</code> in order to delight Arch users <img src='http://therning.org/magnus/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  )</p>

<p>I should probably point out that while epilicious never could be called polished, BMS is even less so.  I might find the time to make it multi-threaded, so that it&#8217;s possible to do some sort of progress dialogue, but don&#8217;t hold your breath.  In the back of my mind is also the thought of rewriting it yet again, in JavaScript/seed.</p>
<ol class="footnotes"><li id="footnote_0_762" class="footnote">The format of <code>.vapi</code> files are unknown to me, and I haven&#8217;t managed to find much documentation.  Using function pointers seemed like an easier way, especially given that I needed this in exactly 3 places.</li></ol><p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Bookmark</a> </p>]]></content:encoded>
			<wfw:commentRss>http://therning.org/magnus/archives/762/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Dents for 2009-10-22</title>
		<link>http://therning.org/magnus/archives/774</link>
		<comments>http://therning.org/magnus/archives/774#comments</comments>
		<pubDate>Thu, 22 Oct 2009 22:59:59 +0000</pubDate>
		<dc:creator>Magnus</dc:creator>
				<category><![CDATA[Posts]]></category>

		<guid isPermaLink="false">http://therning.org/magnus/archives/774</guid>
		<description><![CDATA[#identi.ca I&#8217;m confused, does Twitter config option &#8220;Import my Friends Timeline.&#8221; not mean what I think it does? AFAICT nothing&#8217;s imported. # Dear CNNMoney.com, you need a meta tag for Content-Type on your printer-friendly pages to make sure the character set is set correctly. # I hate shell scripting! # @drewfitzsimmons I too want an [...]]]></description>
			<content:encoded><![CDATA[<ul class="aktt_tweet_digest">
    <li>#identi.ca I&#8217;m confused, does Twitter config option &#8220;Import my Friends Timeline.&#8221; not mean what I think it does? AFAICT nothing&#8217;s imported. <a href="http://identi.ca/notice/5064416174">#</a></li>
    <li>Dear CNNMoney.com, you need a meta tag for Content-Type on your printer-friendly pages to make sure the character set is set correctly. <a href="http://identi.ca/notice/5064503677">#</a></li>
    <li>I hate shell scripting! <a href="http://identi.ca/notice/12642692">#</a></li>
    <li>@drewfitzsimmons I too want an N900, still slightly confused as to what sort of suitable PAYG/subscription different operators offer though. <a href="http://identi.ca/notice/5080903895">#</a></li>
</ul>

<p class="aktt_credit">Powered by modified <a href="http://alexking.org/projects/wordpress">Twitter Tools</a>.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Bookmark</a> </p>]]></content:encoded>
			<wfw:commentRss>http://therning.org/magnus/archives/774/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Updating Haskell packages on Arch</title>
		<link>http://therning.org/magnus/archives/751</link>
		<comments>http://therning.org/magnus/archives/751#comments</comments>
		<pubDate>Sun, 13 Sep 2009 21:24:48 +0000</pubDate>
		<dc:creator>Magnus</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[arch]]></category>
		<category><![CDATA[ghc]]></category>
		<category><![CDATA[haskell]]></category>

		<guid isPermaLink="false">http://therning.org/magnus/?p=751</guid>
		<description><![CDATA[A few days ago I noticed that there were a few Haskell packages on AUR that had received updates. This was the excuse I had been waiting for to address the second part of keeping my Haskell packages up-to-date (I&#8217;ve written about the first part before, dealing with an update to GHC). It&#8217;s easy to [...]]]></description>
			<content:encoded><![CDATA[<p>A few days ago I noticed that there were a few Haskell packages on AUR that
had received updates.  This was the excuse I had been waiting for to address
the second part of keeping my Haskell packages up-to-date (I&#8217;ve written about
the first part before, <a href="http://therning.org/magnus/archives/713">dealing with an update to GHC</a>).</p>

<p>It&#8217;s easy to find the packages with available updates:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">%</span> yaourt <span style="color: #660033;">-Su</span> <span style="color: #660033;">--aur</span></pre></div></div>


<p>Unfortunately it isn&#8217;t as easy as just updating the listed packages.  Any
package that depends on an updated package really should be re-compiled and
re-installed to guarantee that the entire system behaves as expected after the
upgrade.  Of course <code>pacman</code> can handle it:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">%</span> pacman <span style="color: #660033;">-Rcn</span> <span style="color: #000000; font-weight: bold;">&lt;</span>all pkgs with updates<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>


<p>This will list all packages that will be removed.  After removing them all,
they can all be re-installed.  That is of course not quite as nice as it could
be, since they all then will be explicitly installed, it would be nicer to
just re-install the &#8220;top-level packages&#8221;.  This is one way to achieve this.</p>

<p>I did a bit of refactoring and put the Arch-related functions from the
previous post in their own module, <code>Arch</code>.  Then I added a function that takes
a package and recursively inspects <code>Required By</code> until a &#8220;top-level package&#8221;
(i.e. a package that doesn&#8217;t require any other package) is reached:</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">getTopRequiredBy pkg <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">let</span>
        tops <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">do</span>
            first <span style="color: #339933; font-weight: bold;">&lt;-</span> getRequiredBy pkg
            <span style="color: #06c; font-weight: bold;">if</span> <span style="font-weight: bold;">null</span> first
                <span style="color: #06c; font-weight: bold;">then</span> <span style="font-weight: bold;">return</span> <span style="color: green;">&#91;</span>pkg<span style="color: green;">&#93;</span>
                <span style="color: #06c; font-weight: bold;">else</span> liftM <span style="font-weight: bold;">concat</span> <span style="color: #339933; font-weight: bold;">$</span> <span style="font-weight: bold;">mapM</span> getTopRequiredBy first
    <span style="color: #06c; font-weight: bold;">in</span> liftM nub tops</pre></div></div>


<p>After that it&#8217;s straight forward to write up a little tool which offers some
advice on what to do:</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">main <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">do</span>
    pkgsToUpgrade <span style="color: #339933; font-weight: bold;">&lt;-</span> getArgs
    pkgsToReinstall <span style="color: #339933; font-weight: bold;">&lt;-</span> liftM <span style="color: green;">&#40;</span>nub <span style="color: #339933; font-weight: bold;">.</span> <span style="font-weight: bold;">concat</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">$</span> <span style="font-weight: bold;">mapM</span> Arch<span style="color: #339933; font-weight: bold;">.</span>getTopRequiredBy pkgsToUpgrade
    <span style="font-weight: bold;">putStrLn</span> <span style="color: #339933; font-weight: bold;">$</span> <span style="background-color: #3cb371;">&quot;To remove     : pacman -Rnc &quot;</span> <span style="color: #339933; font-weight: bold;">++</span> <span style="font-weight: bold;">unwords</span> pkgsToUpgrade
    <span style="font-weight: bold;">putStrLn</span> <span style="color: #339933; font-weight: bold;">$</span> <span style="background-color: #3cb371;">&quot;To re-install : yaourt -S &quot;</span> <span style="color: #339933; font-weight: bold;">++</span> <span style="font-weight: bold;">unwords</span> pkgsToReinstall</pre></div></div>


<p>Using it on the packages I wanted to upgrade gave the following output:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">%</span> runhaskell PkgUpgrade.hs haskell-<span style="color: #7a0874; font-weight: bold;">&#123;</span>configfile,haxml,json,missingh,safe,testpack,<span style="color: #000000; font-weight: bold;">time</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>
To remove     : pacman <span style="color: #660033;">-Rnc</span> haskell-configfile haskell-haxml haskell-json haskell-missingh haskell-safe haskell-testpack haskell-time
To re-install : yaourt <span style="color: #660033;">-S</span> haskell-configfile haskell-haxml haskell-json haskell-hsh haskell-safe</pre></div></div>


<p>Following that advice seemed to work just like I intended.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Bookmark</a> </p>]]></content:encoded>
			<wfw:commentRss>http://therning.org/magnus/archives/751/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Wrapping IO, part 2</title>
		<link>http://therning.org/magnus/archives/742</link>
		<comments>http://therning.org/magnus/archives/742#comments</comments>
		<pubDate>Mon, 07 Sep 2009 22:17:10 +0000</pubDate>
		<dc:creator>Magnus</dc:creator>
				<category><![CDATA[Posts]]></category>

		<guid isPermaLink="false">http://therning.org/magnus/?p=742</guid>
		<description><![CDATA[The previous post was a fairly silly example, unless of course it&#8217;s more useful than I realise However, here&#8217;s something that I can see a bit more use of, a monad that restricts reading and writing of files to two files, one to read from and one to write to. Again, the first step is [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://therning.org/magnus/archives/738">previous post</a> was a fairly silly example, unless of course it&#8217;s more useful
than I realise <img src='http://therning.org/magnus/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />   However, here&#8217;s something that I can see a bit more use of, a
monad that restricts reading and writing of files to two files, one to read
from and one to write to.</p>

<p>Again, the first step is to create a data type:</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">newtype</span> TwoFileIO a <span style="color: #339933; font-weight: bold;">=</span> TwoFileIO <span style="color: green;">&#123;</span> execTwoFileIO <span style="color: #339933; font-weight: bold;">::</span> <span style="color: green;">&#40;</span>Handle<span style="color: #339933; font-weight: bold;">,</span> Handle<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: #cccc00; font-weight: bold;">IO</span> a <span style="color: green;">&#125;</span></pre></div></div>


<p>This defines a type wrapping a function that takes a pair of handles (one for
input and one for output) and returns an &#8220;IO action&#8221;.  Turning this into a
monad is straight forward (actually it&#8217;s similar to the <a href="http://hackage.haskell.org/packages/archive/mtl/latest/doc/html/Control-Monad-Reader.html#t%3AReader">Reader</a> monad):</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">instance</span> <span style="color: #cccc00; font-weight: bold;">Monad</span> TwoFileIO <span style="color: #06c; font-weight: bold;">where</span>
    <span style="font-weight: bold;">return</span> v <span style="color: #339933; font-weight: bold;">=</span> TwoFileIO <span style="color: #339933; font-weight: bold;">$</span> \ <span style="color: #339933; font-weight: bold;">_</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="font-weight: bold;">return</span> v
    <span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">&gt;&gt;=</span><span style="color: green;">&#41;</span> m f <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">let</span>
            fInIO <span style="color: #339933; font-weight: bold;">=</span> execTwoFileIO <span style="color: #339933; font-weight: bold;">.</span> f
        <span style="color: #06c; font-weight: bold;">in</span> TwoFileIO <span style="color: #339933; font-weight: bold;">$</span> \ hs <span style="color: #339933; font-weight: bold;">-&gt;</span>
            execTwoFileIO m hs <span style="color: #339933; font-weight: bold;">&gt;&gt;=</span> \v <span style="color: #339933; font-weight: bold;">-&gt;</span> fInIO v hs</pre></div></div>


<p>To return a value we can simply drop the pair of handles and return the value
in <code>IO</code>.  Bind (<code>&gt;&gt;=</code>) only looks complicated, what happens is that the first
argument is &#8220;executed&#8221; with the provided handles, then the second argument is
passed the result and executed with the same pair of handles.  Of course the
handles aren&#8217;t actually known yet, so an anynmous function is created, and
wrapped in an instance of <code>TwoFileIO</code>.  That&#8217;s it for the most complicated
part.</p>

<p>In order to avoid having to manually open files and wire everything up I wrote
the following convenience function:</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">runFileIO m iFn oFn <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">do</span>
    iH <span style="color: #339933; font-weight: bold;">&lt;-</span> openFile iFn ReadMode
    oH <span style="color: #339933; font-weight: bold;">&lt;-</span> openFile oFn WriteMode
    res <span style="color: #339933; font-weight: bold;">&lt;-</span> execTwoFileIO m <span style="color: green;">&#40;</span>iH<span style="color: #339933; font-weight: bold;">,</span> oH<span style="color: green;">&#41;</span>
    <span style="font-weight: bold;">mapM_</span> hClose <span style="color: green;">&#91;</span>iH<span style="color: #339933; font-weight: bold;">,</span> oH<span style="color: green;">&#93;</span>
    <span style="font-weight: bold;">return</span> res</pre></div></div>


<p>Yes, it does lack a bit in exception handling, but it&#8217;s good enough for now.</p>

<p>Then I can define the actions/functions that are available inside <code>TwoFileIO</code>.
Reading and writing lines:</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">fioPutStrLn s <span style="color: #339933; font-weight: bold;">=</span> TwoFileIO <span style="color: #339933; font-weight: bold;">$</span> \ <span style="color: green;">&#40;</span>iH<span style="color: #339933; font-weight: bold;">,</span> oH<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">-&gt;</span>
    hPutStrLn oH s
&nbsp;
fioGetLine <span style="color: #339933; font-weight: bold;">=</span> TwoFileIO <span style="color: #339933; font-weight: bold;">$</span> \ <span style="color: green;">&#40;</span>iH<span style="color: #339933; font-weight: bold;">,</span> oH<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">-&gt;</span>
    hGetLine iH</pre></div></div>


<p>Note how it now becomes <em>very hard</em> to mix up the files and accidentally read
from the output file or write to the input file.</p>

<p>As a little test function I used this one, which reads two lines and then
writes them in the reversed order:</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">get1stN2ndPutLast <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">do</span>
    first <span style="color: #339933; font-weight: bold;">&lt;-</span> fioGetLine
    second <span style="color: #339933; font-weight: bold;">&lt;-</span> fioGetLine
    fioPutStrLn second
    fioPutStrLn first</pre></div></div>


<p>I can now test this using <code>ghci</code>:</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #339933; font-weight: bold;">&gt;</span> h <span style="color: #339933; font-weight: bold;">&lt;-</span> openFile <span style="background-color: #3cb371;">&quot;testIn.txt&quot;</span> ReadMode
<span style="color: #339933; font-weight: bold;">&gt;</span> hGetContents h
<span style="background-color: #3cb371;">&quot;line 0<span style="background-color: #3cb371; font-weight: bold;">\n</span>line 1<span style="background-color: #3cb371; font-weight: bold;">\n</span>line 2<span style="background-color: #3cb371; font-weight: bold;">\n</span>&quot;</span>
<span style="color: #339933; font-weight: bold;">&gt;</span> runFileIO get1stN2ndPutLast <span style="background-color: #3cb371;">&quot;testIn.txt&quot;</span> <span style="background-color: #3cb371;">&quot;testOut.txt&quot;</span>
<span style="color: #339933; font-weight: bold;">&gt;</span> h <span style="color: #339933; font-weight: bold;">&lt;-</span> openFile <span style="background-color: #3cb371;">&quot;testOut.txt&quot;</span> ReadMode
<span style="color: #339933; font-weight: bold;">&gt;</span> hGetContents h
<span style="background-color: #3cb371;">&quot;line 1<span style="background-color: #3cb371; font-weight: bold;">\n</span>line 0<span style="background-color: #3cb371; font-weight: bold;">\n</span>&quot;</span></pre></div></div>

<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Bookmark</a> </p>]]></content:encoded>
			<wfw:commentRss>http://therning.org/magnus/archives/742/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Wrapping IO, part 1</title>
		<link>http://therning.org/magnus/archives/738</link>
		<comments>http://therning.org/magnus/archives/738#comments</comments>
		<pubDate>Mon, 07 Sep 2009 22:04:05 +0000</pubDate>
		<dc:creator>Magnus</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[monad]]></category>

		<guid isPermaLink="false">http://therning.org/magnus/?p=738</guid>
		<description><![CDATA[I&#8217;ve many times heard that Haskell can be used to prevent certain kind of programmer mistakes. In a presentation on Darcs it was explained how GADTs (especially phantom types) are used in Darcs to make sure that operations on patches follow certain rules. Another way, and at least it sounds easier, is to limit the [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve many times heard that Haskell can be used to prevent certain kind of
programmer mistakes.  In a <a href="http://www.londonhug.net/2008/02/02/video-darcs-and-gadts/">presentation on Darcs</a> it was explained how
GADTs (especially phantom types) are used in Darcs to make sure that
operations on patches follow certain rules.  Another way, and at least it
sounds easier, is to limit the available functions by running code in
some sort of container.  This being Haskell, that container is often a
monad.  I&#8217;ve really never seen this presented<sup><a href="http://therning.org/magnus/archives/738#footnote_0_738" id="identifier_0_738" class="footnote-link footnote-identifier-link" title="Most probably due do my weak
searching-fu than anything else.">i</a></sup>, so I thought I&#8217;d try to do it, and indeed
it turns out to be very simple.</p>

<p>I started with a data type:</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">newtype</span> HideIO a <span style="color: #339933; font-weight: bold;">=</span> HideIO <span style="color: green;">&#123;</span> runHideIO <span style="color: #339933; font-weight: bold;">::</span> <span style="color: #cccc00; font-weight: bold;">IO</span> a <span style="color: green;">&#125;</span></pre></div></div>


<p>which I then made into a <code>Monad</code> in order to make it easy to work with:</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">instance</span> <span style="color: #cccc00; font-weight: bold;">Monad</span> HideIO <span style="color: #06c; font-weight: bold;">where</span>
    <span style="font-weight: bold;">return</span> <span style="color: #339933; font-weight: bold;">=</span> HideIO <span style="color: #339933; font-weight: bold;">.</span> <span style="font-weight: bold;">return</span>
&nbsp;
    <span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">&gt;&gt;=</span><span style="color: green;">&#41;</span> m f <span style="color: #339933; font-weight: bold;">=</span> HideIO <span style="color: #339933; font-weight: bold;">$</span> runHideIO m <span style="color: #339933; font-weight: bold;">&gt;&gt;=</span> runHideIO <span style="color: #339933; font-weight: bold;">.</span> f</pre></div></div>


<p>Then I can create an IO function that <em>are</em> allowed in the <code>HideIO</code> monad:</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">hioPutStrLn <span style="color: #339933; font-weight: bold;">=</span> HideIO <span style="color: #339933; font-weight: bold;">.</span> <span style="font-weight: bold;">putStrLn</span></pre></div></div>


<p>In <code>ghci</code> I can then do the following:</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #339933; font-weight: bold;">&gt;</span> runHideIO <span style="color: #339933; font-weight: bold;">$</span> hioPutStrLn <span style="background-color: #3cb371;">&quot;Hello, World!&quot;</span>
Hello<span style="color: #339933; font-weight: bold;">,</span> World<span style="color: #339933; font-weight: bold;">!</span></pre></div></div>


<p>But I can&#8217;t do much else.</p>
<ol class="footnotes"><li id="footnote_0_738" class="footnote">Most probably due do my weak
searching-fu than anything else.</li></ol><p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Bookmark</a> </p>]]></content:encoded>
			<wfw:commentRss>http://therning.org/magnus/archives/738/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Trying to work out iteratees</title>
		<link>http://therning.org/magnus/archives/735</link>
		<comments>http://therning.org/magnus/archives/735#comments</comments>
		<pubDate>Wed, 26 Aug 2009 22:30:03 +0000</pubDate>
		<dc:creator>Magnus</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[enumerator]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[iteratee]]></category>

		<guid isPermaLink="false">http://therning.org/magnus/?p=735</guid>
		<description><![CDATA[A few days ago I decided to explore the idea of using iteratee to do IO in Haskell. I read most of what Oleg has written on input processing using left-fold enumerators. Only a little wiser I took a look at the Iteratee IO package on Hackage. Unfortunately it still hadn&#8217;t quite sunk in. To [...]]]></description>
			<content:encoded><![CDATA[<p>A few days ago I decided to explore the idea of using iteratee to do IO in Haskell.  I read most of what Oleg has written on <a href="http://okmij.org/ftp/Streams.html">input processing using left-fold enumerators</a>.  Only a little wiser I took a look at the <a href="http://hackage.haskell.org/package/iteratee">Iteratee IO package on Hackage</a>.  Unfortunately it still hadn&#8217;t quite sunk in.  To be honest I couldn&#8217;t quite make heads or tails of it.  Often just lining up the types properly will just work, even if I don&#8217;t understand why<sup><a href="http://therning.org/magnus/archives/735#footnote_0_735" id="identifier_0_735" class="footnote-link footnote-identifier-link" title="This reminds me of a math professor I had at university who said something like: &amp;#8220;When it feels like the pen understands more than your head, persevere!  It means you are close to getting it.&amp;#8221;">i</a></sup> and soon after I usually gain some sort of understanding. This strategy didn&#8217;t seem to work with this particular package though <img src='http://therning.org/magnus/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>

<p>Somewhat based on Don&#8217;s answer to <a href="http://stackoverflow.com/questions/1319705/introduction-or-simple-examples-for-iteratee">my question on Stackoverflow.com</a> I thought I&#8217;d try to work through an implementation of my own.  I just really hope I&#8217;ve got it right <img src='http://therning.org/magnus/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>

<p>I must admit I used <code>Iteratee</code> for inspiration at times.  However, I couldn&#8217;t copy it straight off since I decided to first implement iteratee without involving monads.  Sure, it&#8217;s rather silly to do &#8220;input processing&#8221; in Haskell without involving monads, but I find that including monads often clouds the problem at hand.  So, I left them out to begin with, and add them again once I feel I know what I&#8217;m doing.  So, here goes nothing&#8230;</p>

<p>The basic idea is to process a stream of data, presented in chunks.  Each chunk is handed to an iteratee by an enumerator.  For each chunk the iteratee signals to the enumerator whether it&#8217;s done or requires more data.  These are the types I cooked up for this.</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">data</span> Stream c e
    <span style="color: #339933; font-weight: bold;">=</span> Eof
    <span style="color: #339933; font-weight: bold;">|</span> Chunk <span style="color: green;">&#40;</span>c e<span style="color: green;">&#41;</span>
&nbsp;
<span style="color: #06c; font-weight: bold;">data</span> Stepper c e a
    <span style="color: #339933; font-weight: bold;">=</span> Done a <span style="color: green;">&#40;</span>Stream c e<span style="color: green;">&#41;</span>
    <span style="color: #339933; font-weight: bold;">|</span> NeedAnotherChunk <span style="color: green;">&#40;</span>Iteratee c e a<span style="color: green;">&#41;</span>
&nbsp;
<span style="color: #06c; font-weight: bold;">data</span> Iteratee c e a <span style="color: #339933; font-weight: bold;">=</span> Iteratee
    <span style="color: green;">&#123;</span> runIteratee <span style="color: #339933; font-weight: bold;">::</span> <span style="color: green;">&#40;</span>Stream c e<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: green;">&#40;</span>Stepper c e a<span style="color: green;">&#41;</span> <span style="color: green;">&#125;</span>
&nbsp;
<span style="color: #06c; font-weight: bold;">type</span> Enumerator c e a <span style="color: #339933; font-weight: bold;">=</span> Iteratee c e a <span style="color: #339933; font-weight: bold;">-&gt;</span> Iteratee c e a</pre></div></div>


<p>I found it rather useful to implement <code>Show</code> for the two first, but I&#8217;ll leave that out of this post since it&#8217;s a simple thing to do.</p>

<p>I should probably point out that the container type for the stream (that&#8217;s the &#8216;c&#8217; in <code>Stream c e</code>) is rather pointless in what I&#8217;ve done; it&#8217;s always going to be <code>[]</code> in this post.  Keeping it in does provide some more similarity with the <code>Iteratee</code> on Hackage.</p>

<p>At this point I jumped to turning a list into an enumerator.  The way I implemented it the list is split up in chunk of 3 items and present each chunk in order to the passed in iteratee.</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">enumList l iter <span style="color: #339933; font-weight: bold;">=</span> loop grouped iter
    <span style="color: #06c; font-weight: bold;">where</span>
        grouped <span style="color: #339933; font-weight: bold;">=</span> groupList <span style="color: red;">3</span> l
&nbsp;
        groupList n l <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">let</span>
                <span style="color: green;">&#40;</span>p<span style="color: #339933; font-weight: bold;">,</span> r<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> <span style="font-weight: bold;">splitAt</span> n l
            <span style="color: #06c; font-weight: bold;">in</span> <span style="color: #06c; font-weight: bold;">case</span> p <span style="color: #06c; font-weight: bold;">of</span>
                <span style="color: green;">&#91;</span><span style="color: green;">&#93;</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: green;">&#91;</span><span style="color: green;">&#93;</span>
                xs <span style="color: #339933; font-weight: bold;">-&gt;</span> xs:groupList n r</pre></div></div>


<p>The <code>loop</code> function is the main part.  Ending when the chunks are all used up is the easy part:</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">        loop <span style="color: green;">&#91;</span><span style="color: green;">&#93;</span> i <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">let</span>
                s <span style="color: #339933; font-weight: bold;">=</span> runIteratee i Eof
            <span style="color: #06c; font-weight: bold;">in</span> <span style="color: #06c; font-weight: bold;">case</span> s <span style="color: #06c; font-weight: bold;">of</span>
                Done v str <span style="color: #339933; font-weight: bold;">-&gt;</span> Iteratee <span style="color: #339933; font-weight: bold;">$</span> \ <span style="color: #339933; font-weight: bold;">_</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> s
                NeedAnotherChunk i <span style="color: #339933; font-weight: bold;">-&gt;</span> i</pre></div></div>


<p>It is arguably an error if the iteratee returns <code>NeedAnotherChunk</code> when passed an <code>Eof</code> stream, but for now I&#8217;ll leave it the way it is.  Doing the recursive step is very similar:</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">        loop <span style="color: green;">&#40;</span>x:xs<span style="color: green;">&#41;</span> i <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">let</span>
                s <span style="color: #339933; font-weight: bold;">=</span> runIteratee i <span style="color: green;">&#40;</span>Chunk x<span style="color: green;">&#41;</span>
            <span style="color: #06c; font-weight: bold;">in</span> <span style="color: #06c; font-weight: bold;">case</span> s <span style="color: #06c; font-weight: bold;">of</span>
                Done v str <span style="color: #339933; font-weight: bold;">-&gt;</span> Iteratee <span style="color: #339933; font-weight: bold;">$</span> \ <span style="color: #339933; font-weight: bold;">_</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> s
                NeedAnotherChunk i' <span style="color: #339933; font-weight: bold;">-&gt;</span> loop xs i'</pre></div></div>


<p>Here it is worth noticing that the iteratee is expected to return any part of the chunk that wasn&#8217;t processed.</p>

<p>Next I coded up my first iteratee, a map over the stream:</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">iFMap f <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">let</span>
        doAcc acc Eof <span style="color: #339933; font-weight: bold;">=</span> Done acc Eof
        doAcc acc <span style="color: green;">&#40;</span>Chunk i<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> NeedAnotherChunk <span style="color: #339933; font-weight: bold;">$</span> Iteratee <span style="color: #339933; font-weight: bold;">$</span> doAcc <span style="color: green;">&#40;</span>acc `mappend` <span style="color: green;">&#40;</span><span style="font-weight: bold;">fmap</span> f i<span style="color: green;">&#41;</span><span style="color: green;">&#41;</span>
    <span style="color: #06c; font-weight: bold;">in</span> Iteratee <span style="color: #339933; font-weight: bold;">$</span> doAcc mempty</pre></div></div>


<p>Now I can run the iterator over a list enumerator:</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #339933; font-weight: bold;">&gt;</span> runIteratee <span style="color: green;">&#40;</span>enumList <span style="color: green;">&#91;</span>1<span style="color: #339933; font-weight: bold;">..</span>9<span style="color: green;">&#93;</span> <span style="color: green;">&#40;</span>iFMap <span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">*</span><span style="color: red;">2</span><span style="color: green;">&#41;</span><span style="color: green;">&#41;</span><span style="color: green;">&#41;</span> Eof
Stepper Done <span style="color: #339933; font-weight: bold;">&lt;&lt;</span><span style="color: green;">&#91;</span><span style="color: red;">2</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">4</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">6</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">8</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">10</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">12</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">14</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">16</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">18</span><span style="color: green;">&#93;</span><span style="color: #339933; font-weight: bold;">&gt;&gt;</span> <span style="color: #339933; font-weight: bold;">&lt;&lt;</span>Stream: Eof<span style="color: #339933; font-weight: bold;">&gt;&gt;</span></pre></div></div>


<p>I found that a bit verbose, especially for interactive experimentation so the following simplifies it a bit</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">run iter <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">case</span> <span style="color: green;">&#40;</span>runIteratee iter<span style="color: green;">&#41;</span> Eof <span style="color: #06c; font-weight: bold;">of</span>
    Done a <span style="color: #339933; font-weight: bold;">_</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> a
    NeedAnotherChunk <span style="color: #339933; font-weight: bold;">_</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="font-weight: bold;">error</span> <span style="background-color: #3cb371;">&quot;run: Iterator didn't finish on Eof&quot;</span></pre></div></div>


<p>As Oleg pointed out in his writings it turns out that <code>Iteratee c e</code> is a monad.</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">instance</span> <span style="color: #cccc00; font-weight: bold;">Monad</span> <span style="color: green;">&#40;</span>Iteratee c e<span style="color: green;">&#41;</span> <span style="color: #06c; font-weight: bold;">where</span>
    <span style="font-weight: bold;">return</span> x <span style="color: #339933; font-weight: bold;">=</span> Iteratee <span style="color: #339933; font-weight: bold;">$</span> \ s <span style="color: #339933; font-weight: bold;">-&gt;</span> Done x s</pre></div></div>


<p>The implementation of <code>return</code> is obvious, there really isn&#8217;t any other option than to encode is a continuation that returns <code>Done</code> irrespective of what is offered, and passes along the rest of the stream no matter what&#8217;s passed in.  Bind (<code>&gt;&gt;=</code>) is a bit more complicated:</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">    i <span style="color: #339933; font-weight: bold;">&gt;&gt;=</span> f <span style="color: #339933; font-weight: bold;">=</span> Iteratee <span style="color: #339933; font-weight: bold;">$</span> \ s <span style="color: #339933; font-weight: bold;">-&gt;</span>
        <span style="color: #06c; font-weight: bold;">let</span>
            c <span style="color: #339933; font-weight: bold;">=</span> runIteratee i s
        <span style="color: #06c; font-weight: bold;">in</span> <span style="color: #06c; font-weight: bold;">case</span> c <span style="color: #06c; font-weight: bold;">of</span>
            Done v str <span style="color: #339933; font-weight: bold;">-&gt;</span> runIteratee <span style="color: green;">&#40;</span>f v<span style="color: green;">&#41;</span> str
            NeedAnotherChunk i' <span style="color: #339933; font-weight: bold;">-&gt;</span> NeedAnotherChunk <span style="color: #339933; font-weight: bold;">$</span> i' <span style="color: #339933; font-weight: bold;">&gt;&gt;=</span> f</pre></div></div>


<p>My understanding is that the left iteratee should be stepped along until it returns <code>Done</code>, at that point the result is passed to the right-side function, which results in an iteratee.  The rest of the stream is then passed on to the new iteratee.</p>

<p>I implemented two other iteratees, <code>iDrop :: Int -&gt; Iteratee [] e ()</code> and <code>iTakeWhile :: (e -&gt; Bool) -&gt; Iteratee [] e [e]</code> with the obvious implementations.  This then allows me to write a little test like this:</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">iTest <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">do</span>
    iDrop <span style="color: red;">2</span>
    t <span style="color: #339933; font-weight: bold;">&lt;-</span> iTakeWhile <span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">&lt;</span> <span style="color: red;">5</span><span style="color: green;">&#41;</span>
    a <span style="color: #339933; font-weight: bold;">&lt;-</span> <span style="font-weight: bold;">return</span> 'c'
    m <span style="color: #339933; font-weight: bold;">&lt;-</span> iFMap <span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">+</span> <span style="color: red;">3</span><span style="color: green;">&#41;</span>
    <span style="font-weight: bold;">return</span> <span style="color: green;">&#40;</span>t<span style="color: #339933; font-weight: bold;">,</span> a<span style="color: #339933; font-weight: bold;">,</span> m<span style="color: green;">&#41;</span></pre></div></div>


<p>Running it gives the expected result:</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #339933; font-weight: bold;">&gt;</span> run <span style="color: green;">&#40;</span>enumList <span style="color: green;">&#91;</span>1<span style="color: #339933; font-weight: bold;">..</span>9<span style="color: green;">&#93;</span> iTest<span style="color: green;">&#41;</span>
<span style="color: green;">&#40;</span><span style="color: green;">&#91;</span><span style="color: red;">3</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">4</span><span style="color: green;">&#93;</span><span style="color: #339933; font-weight: bold;">,</span>'c'<span style="color: #339933; font-weight: bold;">,</span><span style="color: green;">&#91;</span><span style="color: red;">8</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">9</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">10</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">11</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">12</span><span style="color: green;">&#93;</span><span style="color: green;">&#41;</span></pre></div></div>


<p>That&#8217;s pretty much it.  Not that much to it.  At least not as long as I&#8217;ve actually understood iteratees.</p>
<ol class="footnotes"><li id="footnote_0_735" class="footnote">This reminds me of a math professor I had at university who said something like: &#8220;When it feels like the pen understands more than your head, persevere!  It means you are close to getting it.&#8221;</li></ol><p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Bookmark</a> </p>]]></content:encoded>
			<wfw:commentRss>http://therning.org/magnus/archives/735/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Making a choice from a list in Haskell, Vty (part 5, the last one)</title>
		<link>http://therning.org/magnus/archives/732</link>
		<comments>http://therning.org/magnus/archives/732#comments</comments>
		<pubDate>Sun, 23 Aug 2009 20:23:38 +0000</pubDate>
		<dc:creator>Magnus</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[vty]]></category>

		<guid isPermaLink="false">http://therning.org/magnus/?p=732</guid>
		<description><![CDATA[The time has come for the final installment of this series of &#8220;discussions of a refactoring&#8221;. These are the earlier installments. This is where I finally add the ability to collapse a list item. This is a rather terse description of the changes, since I feel all of them are fairly obvious, and hence require [...]]]></description>
			<content:encoded><![CDATA[<p>The time has come for the final installment of this series of &#8220;discussions of a refactoring&#8221;.  <a href="http://therning.org/magnus/archives/710">These</a> <a href="http://therning.org/magnus/archives/702">are</a> <a href="http://therning.org/magnus/archives/689">the</a> <a href="http://therning.org/magnus/archives/685">earlier</a> <a href="http://therning.org/magnus/archives/664">installments</a>.  This is where I finally add the ability to collapse a list item.  This is a rather terse description of the changes, since I feel all of them are fairly obvious, and hence require no lengthy explanation.</p>

<p>First the <code>Option</code> type has to be changed to keep track of whether an item is collapsed or not:</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">data</span> Option <span style="color: #339933; font-weight: bold;">=</span> Option
    <span style="color: green;">&#123;</span> optionRange<span style="color: #339933; font-weight: bold;">::</span><span style="color: green;">&#40;</span><span style="color: #cccc00; font-weight: bold;">Int</span><span style="color: #339933; font-weight: bold;">,</span> <span style="color: #cccc00; font-weight: bold;">Int</span><span style="color: green;">&#41;</span>
    <span style="color: #339933; font-weight: bold;">,</span> optionCollapsed<span style="color: #339933; font-weight: bold;">::</span><span style="color: #cccc00; font-weight: bold;">Bool</span>
    <span style="color: #339933; font-weight: bold;">,</span> optionS1<span style="color: #339933; font-weight: bold;">::</span><span style="color: #cccc00; font-weight: bold;">String</span>
    <span style="color: #339933; font-weight: bold;">,</span> optionS2<span style="color: #339933; font-weight: bold;">::</span><span style="color: #cccc00; font-weight: bold;">String</span>
    <span style="color: green;">&#125;</span> <span style="color: #06c; font-weight: bold;">deriving</span> <span style="color: green;">&#40;</span><span style="color: #cccc00; font-weight: bold;">Show</span><span style="color: green;">&#41;</span></pre></div></div>


<p>Next the rendering of an item has to be changed, so that collapsed items really appear collapsed.  I thought displaying a collapsed item as its first line, with &#8220;&#8230;&#8221; added to the end would be acceptable for a first version:</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">instance</span> Pretty Option <span style="color: #06c; font-weight: bold;">where</span>
    pretty <span style="color: green;">&#40;</span>Option <span style="color: #339933; font-weight: bold;">_</span> False s1 s2<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> string s1 <span style="color: #339933; font-weight: bold;">&lt;&gt;</span> line <span style="color: #339933; font-weight: bold;">&lt;&gt;</span> indent <span style="color: red;">2</span> <span style="color: green;">&#40;</span>string s2<span style="color: green;">&#41;</span>
    pretty <span style="color: green;">&#40;</span>Option <span style="color: #339933; font-weight: bold;">_</span> True s1 <span style="color: #339933; font-weight: bold;">_</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> string s1 <span style="color: #339933; font-weight: bold;">&lt;&gt;</span> string <span style="background-color: #3cb371;">&quot;...&quot;</span></pre></div></div>


<p>Later on I&#8217;ll need to update the range of an item.  For the forgetful, the range of an item is the starting and ending line.  Obviously the range changes when an item is collapsed:</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">optionUpdateRange o <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">let</span>
        <span style="color: green;">&#40;</span>b<span style="color: #339933; font-weight: bold;">,</span> <span style="color: #339933; font-weight: bold;">_</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> optionRange o
        l <span style="color: #339933; font-weight: bold;">=</span> <span style="font-weight: bold;">length</span> <span style="color: #339933; font-weight: bold;">$</span> <span style="font-weight: bold;">lines</span> <span style="color: #339933; font-weight: bold;">$</span> <span style="font-weight: bold;">show</span> <span style="color: #339933; font-weight: bold;">$</span> pretty o
    <span style="color: #06c; font-weight: bold;">in</span> o <span style="color: green;">&#123;</span> optionRange <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#40;</span>b<span style="color: #339933; font-weight: bold;">,</span> b <span style="color: #339933; font-weight: bold;">+</span> l <span style="color: #339933; font-weight: bold;">-</span> <span style="color: red;">1</span><span style="color: green;">&#41;</span> <span style="color: green;">&#125;</span></pre></div></div>


<p>The implementation of <code>optionsIsInRange</code> has to change due to adding the <code>optionCollapsed</code> field.  It&#8217;ll also be useful to have a few functions for manipulating the collapsed state of an item:</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">optionIsInRange <span style="color: green;">&#40;</span>Option <span style="color: green;">&#40;</span>b<span style="color: #339933; font-weight: bold;">,</span> e<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">_</span> <span style="color: #339933; font-weight: bold;">_</span> <span style="color: #339933; font-weight: bold;">_</span><span style="color: green;">&#41;</span> i <span style="color: #339933; font-weight: bold;">=</span> b <span style="color: #339933; font-weight: bold;">&lt;=</span> i <span style="color: #339933; font-weight: bold;">&amp;&amp;</span> i <span style="color: #339933; font-weight: bold;">&lt;=</span> e
&nbsp;
optionIsCollapsed <span style="color: green;">&#40;</span>Option <span style="color: #339933; font-weight: bold;">_</span> c <span style="color: #339933; font-weight: bold;">_</span> <span style="color: #339933; font-weight: bold;">_</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> c
optionToggleCollapse o <span style="color: #339933; font-weight: bold;">=</span> o <span style="color: green;">&#123;</span> optionCollapsed <span style="color: #339933; font-weight: bold;">=</span> <span style="font-weight: bold;">not</span> <span style="color: green;">&#40;</span>optionCollapsed o<span style="color: green;">&#41;</span> <span style="color: green;">&#125;</span>
optionCollapse o <span style="color: #339933; font-weight: bold;">=</span> o <span style="color: green;">&#123;</span> optionCollapsed <span style="color: #339933; font-weight: bold;">=</span> True <span style="color: green;">&#125;</span>
optionExpand o <span style="color: #339933; font-weight: bold;">=</span> o <span style="color: green;">&#123;</span> optionCollapsed <span style="color: #339933; font-weight: bold;">=</span> False <span style="color: green;">&#125;</span></pre></div></div>


<p>One thing that I didn&#8217;t think about until after doing some manual testing was that moving the cursor up in the list should always put the cursor on the line above, even when moving from one item to the previous.  This was a bug in the previous version <img src='http://therning.org/magnus/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">ozPreviousLine o<span style="color: #339933; font-weight: bold;">@</span><span style="color: green;">&#40;</span>OptionZipper <span style="color: red;">0</span> <span style="color: #339933; font-weight: bold;">_</span> <span style="color: #339933; font-weight: bold;">_</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> o
ozPreviousLine o <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">let</span>
        c <span style="color: #339933; font-weight: bold;">=</span> fromJust <span style="color: #339933; font-weight: bold;">$</span> ozCursor o
        i <span style="color: #339933; font-weight: bold;">=</span> ozIdx o
    <span style="color: #06c; font-weight: bold;">in</span> <span style="color: #06c; font-weight: bold;">if</span> optionIsInRange c <span style="color: green;">&#40;</span>i <span style="color: #339933; font-weight: bold;">-</span> <span style="color: red;">1</span><span style="color: green;">&#41;</span>
        <span style="color: #06c; font-weight: bold;">then</span> o <span style="color: green;">&#123;</span> ozIdx <span style="color: #339933; font-weight: bold;">=</span> i <span style="color: #339933; font-weight: bold;">-</span> <span style="color: red;">1</span> <span style="color: green;">&#125;</span>
        <span style="color: #06c; font-weight: bold;">else</span> ozJumpToCursorBottom <span style="color: #339933; font-weight: bold;">$</span> ozLeft o</pre></div></div>


<p>I also have to change <code>ozCursorMod</code> due to adding the new field:</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">ozCursorMod f o<span style="color: #339933; font-weight: bold;">@</span><span style="color: green;">&#40;</span>OptionZipper <span style="color: #339933; font-weight: bold;">_</span> <span style="color: #339933; font-weight: bold;">_</span> <span style="color: green;">&#40;</span>r:rs<span style="color: green;">&#41;</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">let</span>
        <span style="color: #339933; font-weight: bold;">_</span>r <span style="color: #339933; font-weight: bold;">=</span> f r
    <span style="color: #06c; font-weight: bold;">in</span> o <span style="color: green;">&#123;</span> ozRS <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">_</span>r:rs<span style="color: green;">&#41;</span> <span style="color: green;">&#125;</span>
ozCursorMod <span style="color: #339933; font-weight: bold;">_</span> o <span style="color: #339933; font-weight: bold;">=</span> o</pre></div></div>


<p>It turns out the be useful to be able to jump to the top and bottom of an item (there&#8217;s already an example of the latter above):</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">ozJumpToCursorTop o<span style="color: #339933; font-weight: bold;">@</span><span style="color: green;">&#40;</span>OptionZipper <span style="color: #339933; font-weight: bold;">_</span> <span style="color: #339933; font-weight: bold;">_</span> <span style="color: green;">&#40;</span>r:rs<span style="color: green;">&#41;</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">let</span>
        <span style="color: green;">&#40;</span>newIdx<span style="color: #339933; font-weight: bold;">,</span> <span style="color: #339933; font-weight: bold;">_</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> optionRange r
    <span style="color: #06c; font-weight: bold;">in</span> o <span style="color: green;">&#123;</span> ozIdx <span style="color: #339933; font-weight: bold;">=</span> newIdx <span style="color: green;">&#125;</span>
&nbsp;
ozJumpToCursorBottom o<span style="color: #339933; font-weight: bold;">@</span><span style="color: green;">&#40;</span>OptionZipper <span style="color: #339933; font-weight: bold;">_</span> <span style="color: #339933; font-weight: bold;">_</span> <span style="color: green;">&#40;</span>r:rs<span style="color: green;">&#41;</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">let</span>
        <span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">_,</span> newIdx<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> optionRange r
    <span style="color: #06c; font-weight: bold;">in</span> o <span style="color: green;">&#123;</span> ozIdx <span style="color: #339933; font-weight: bold;">=</span> newIdx <span style="color: green;">&#125;</span></pre></div></div>


<p>Creating the list of items need a slight modification as well:</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">options <span style="color: #339933; font-weight: bold;">=</span> ozFromListWithMod <span style="color: green;">&#40;</span>optionSetRange <span style="color: red;">0</span><span style="color: green;">&#41;</span> <span style="color: green;">&#91;</span>Option <span style="color: green;">&#40;</span><span style="color: red;">0</span><span style="color: #339933; font-weight: bold;">,</span> <span style="color: red;">0</span><span style="color: green;">&#41;</span> False <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span><span style="font-weight: bold;">show</span> i<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">++</span> <span style="background-color: #3cb371;">&quot; Foo&quot;</span><span style="color: green;">&#41;</span> <span style="background-color: #3cb371;">&quot;Bar&quot;</span> <span style="color: #339933; font-weight: bold;">|</span> i <span style="color: #339933; font-weight: bold;">&lt;-</span> <span style="color: green;">&#91;</span>0<span style="color: #339933; font-weight: bold;">..</span>2<span style="color: green;">&#93;</span><span style="color: green;">&#93;</span></pre></div></div>


<p>The last change is adding actually collapsing of an item in the UI controller code:</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #339933; font-weight: bold;">_</span>getChoice vt opts sx sy <span style="color: #339933; font-weight: bold;">=</span>
    <span style="color: #06c; font-weight: bold;">let</span>
        <span style="color: #339933; font-weight: bold;">_</span>converted<span style="color: #339933; font-weight: bold;">_</span>opts <span style="color: #339933; font-weight: bold;">=</span> <span style="font-weight: bold;">lines</span> <span style="color: #339933; font-weight: bold;">$</span> <span style="font-weight: bold;">show</span> <span style="color: #339933; font-weight: bold;">$</span> pretty opts
        <span style="color: #339933; font-weight: bold;">_</span>idx <span style="color: #339933; font-weight: bold;">=</span> ozIdx opts
        <span style="color: #339933; font-weight: bold;">_</span>calcTop winHeight listLength idx <span style="color: #339933; font-weight: bold;">=</span> <span style="font-weight: bold;">max</span> <span style="color: red;">0</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span><span style="font-weight: bold;">min</span> listLength <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span><span style="font-weight: bold;">max</span> <span style="color: red;">0</span> <span style="color: green;">&#40;</span>idx <span style="color: #339933; font-weight: bold;">-</span> winHeight `<span style="font-weight: bold;">div</span>` <span style="color: red;">2</span><span style="color: green;">&#41;</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">+</span> winHeight<span style="color: green;">&#41;</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">-</span> winHeight<span style="color: green;">&#41;</span>
        <span style="color: #339933; font-weight: bold;">_</span>top <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #339933; font-weight: bold;">_</span>calcTop sy <span style="color: green;">&#40;</span><span style="font-weight: bold;">length</span> <span style="color: #339933; font-weight: bold;">_</span>converted<span style="color: #339933; font-weight: bold;">_</span>opts<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">_</span>idx
        <span style="color: #339933; font-weight: bold;">_</span>visible<span style="color: #339933; font-weight: bold;">_</span>opts <span style="color: #339933; font-weight: bold;">=</span> <span style="font-weight: bold;">take</span> sy <span style="color: green;">&#40;</span><span style="font-weight: bold;">drop</span> <span style="color: #339933; font-weight: bold;">_</span>top <span style="color: #339933; font-weight: bold;">_</span>converted<span style="color: #339933; font-weight: bold;">_</span>opts<span style="color: green;">&#41;</span>
    <span style="color: #06c; font-weight: bold;">in</span> <span style="color: #06c; font-weight: bold;">do</span>
        update vt <span style="color: green;">&#40;</span>render <span style="color: #339933; font-weight: bold;">_</span>visible<span style="color: #339933; font-weight: bold;">_</span>opts <span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">_</span>idx <span style="color: #339933; font-weight: bold;">-</span> <span style="color: #339933; font-weight: bold;">_</span>top<span style="color: green;">&#41;</span> sx<span style="color: green;">&#41;</span>
        k <span style="color: #339933; font-weight: bold;">&lt;-</span> getEvent vt
        <span style="color: #06c; font-weight: bold;">case</span> k <span style="color: #06c; font-weight: bold;">of</span>
            EvKey <span style="color: green;">&#40;</span>KASCII ' '<span style="color: green;">&#41;</span> <span style="color: green;">&#91;</span><span style="color: green;">&#93;</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: #06c; font-weight: bold;">let</span>
                    newOpts <span style="color: #339933; font-weight: bold;">=</span> ozJumpToCursorTop <span style="color: #339933; font-weight: bold;">$</span> ozCursorMod <span style="color: green;">&#40;</span>optionUpdateRange <span style="color: #339933; font-weight: bold;">.</span> optionToggleCollapse<span style="color: green;">&#41;</span> opts
                <span style="color: #06c; font-weight: bold;">in</span> <span style="color: #339933; font-weight: bold;">_</span>getChoice vt newOpts sx sy
            EvKey KDown <span style="color: green;">&#91;</span><span style="color: green;">&#93;</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: #339933; font-weight: bold;">_</span>getChoice vt <span style="color: green;">&#40;</span>ozNextLine opts<span style="color: green;">&#41;</span> sx sy
            EvKey KUp <span style="color: green;">&#91;</span><span style="color: green;">&#93;</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: #339933; font-weight: bold;">_</span>getChoice vt <span style="color: green;">&#40;</span>ozPreviousLine opts<span style="color: green;">&#41;</span> sx sy
            EvKey KEsc <span style="color: green;">&#91;</span><span style="color: green;">&#93;</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> shutdown vt <span style="color: #339933; font-weight: bold;">&gt;&gt;</span> <span style="font-weight: bold;">return</span> Nothing
            EvKey KEnter <span style="color: green;">&#91;</span><span style="color: green;">&#93;</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> shutdown vt <span style="color: #339933; font-weight: bold;">&gt;&gt;</span> <span style="font-weight: bold;">return</span> <span style="color: green;">&#40;</span>Just <span style="color: #339933; font-weight: bold;">$</span> <span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">_</span>idx<span style="color: #339933; font-weight: bold;">,</span> ozCursor opts<span style="color: green;">&#41;</span><span style="color: green;">&#41;</span>
            EvResize nx ny <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: #339933; font-weight: bold;">_</span>getChoice vt opts nx ny
            <span style="color: #339933; font-weight: bold;">_</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: #339933; font-weight: bold;">_</span>getChoice vt opts sx sy</pre></div></div>


<p>That&#8217;s it.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Bookmark</a> </p>]]></content:encoded>
			<wfw:commentRss>http://therning.org/magnus/archives/732/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fork/exec in Haskell</title>
		<link>http://therning.org/magnus/archives/727</link>
		<comments>http://therning.org/magnus/archives/727#comments</comments>
		<pubDate>Fri, 21 Aug 2009 15:42:57 +0000</pubDate>
		<dc:creator>Magnus</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[exec]]></category>
		<category><![CDATA[fork]]></category>
		<category><![CDATA[haskell]]></category>

		<guid isPermaLink="false">http://therning.org/magnus/?p=727</guid>
		<description><![CDATA[Here&#8217;s some simple code I put together. I&#8217;m mostly posting it so I won&#8217;t have any problems finding it in the future. module Main where &#160; import Control.Monad import System.Exit import System.Posix.IO import System.Posix.Process &#160; executeChild = do mapM_ closeFd &#91;stdInput, stdOutput, stdError&#93; devnull &#60;- openFd &#34;/dev/null&#34; ReadWrite Nothing defaultFileFlags dup devnull; dup devnull executeFile [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s some simple code I put together.  I&#8217;m mostly posting it so I won&#8217;t have any problems finding it in the future.</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">module</span> Main <span style="color: #06c; font-weight: bold;">where</span>
&nbsp;
<span style="color: #06c; font-weight: bold;">import</span> Control<span style="color: #339933; font-weight: bold;">.</span><span style="color: #cccc00; font-weight: bold;">Monad</span>
<span style="color: #06c; font-weight: bold;">import</span> System<span style="color: #339933; font-weight: bold;">.</span>Exit
<span style="color: #06c; font-weight: bold;">import</span> System<span style="color: #339933; font-weight: bold;">.</span>Posix<span style="color: #339933; font-weight: bold;">.</span><span style="color: #cccc00; font-weight: bold;">IO</span>
<span style="color: #06c; font-weight: bold;">import</span> System<span style="color: #339933; font-weight: bold;">.</span>Posix<span style="color: #339933; font-weight: bold;">.</span>Process
&nbsp;
executeChild <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">do</span>
    <span style="font-weight: bold;">mapM_</span> closeFd <span style="color: green;">&#91;</span>stdInput<span style="color: #339933; font-weight: bold;">,</span> stdOutput<span style="color: #339933; font-weight: bold;">,</span> stdError<span style="color: green;">&#93;</span>
    devnull <span style="color: #339933; font-weight: bold;">&lt;-</span> openFd <span style="background-color: #3cb371;">&quot;/dev/null&quot;</span> ReadWrite Nothing defaultFileFlags
    dup devnull; dup devnull
    executeFile <span style="background-color: #3cb371;">&quot;./Child&quot;</span> False <span style="color: green;">&#91;</span><span style="color: green;">&#93;</span> Nothing
&nbsp;
main <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">do</span>
    child <span style="color: #339933; font-weight: bold;">&lt;-</span> forkProcess executeChild
    <span style="font-weight: bold;">putStrLn</span> <span style="background-color: #3cb371;">&quot;ForkExec: main - forked, going to wait&quot;</span>
    s <span style="color: #339933; font-weight: bold;">&lt;-</span> getProcessStatus True True child
    <span style="color: #06c; font-weight: bold;">case</span> s <span style="color: #06c; font-weight: bold;">of</span>
        Nothing <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: #5d478b; font-style: italic;">-- this shouldn't happen, ever</span>
            <span style="font-weight: bold;">print</span> s <span style="color: #339933; font-weight: bold;">&gt;&gt;</span>  exitFailure
        Just s <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: #06c; font-weight: bold;">do</span>
            <span style="font-weight: bold;">print</span> s
            <span style="color: #06c; font-weight: bold;">case</span> s <span style="color: #06c; font-weight: bold;">of</span>
                Exited <span style="color: #339933; font-weight: bold;">_</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="font-weight: bold;">putStrLn</span> <span style="background-color: #3cb371;">&quot;Child exited properly, though possibly unsuccessfully&quot;</span>
                Terminated <span style="color: #339933; font-weight: bold;">_</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="font-weight: bold;">putStrLn</span> <span style="background-color: #3cb371;">&quot;Terminated!&quot;</span>
                Stopped <span style="color: #339933; font-weight: bold;">_</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="font-weight: bold;">putStrLn</span> <span style="background-color: #3cb371;">&quot;Stopped (only SIGSTOP?)&quot;</span>
            exitSuccess
    exitFailure</pre></div></div>


<p>It&#8217;d be really nice to be able to, after the fork, close <em>all</em> open file descriptors in the child.  But how can I find all the open file descriptors in a process?  Ideally it should be fairly portable, though portability to major Unix/Linux systems is enough for me.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Bookmark</a> </p>]]></content:encoded>
			<wfw:commentRss>http://therning.org/magnus/archives/727/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>JSON in Haskell</title>
		<link>http://therning.org/magnus/archives/719</link>
		<comments>http://therning.org/magnus/archives/719#comments</comments>
		<pubDate>Sun, 16 Aug 2009 21:00:33 +0000</pubDate>
		<dc:creator>Magnus</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[json]]></category>

		<guid isPermaLink="false">http://therning.org/magnus/?p=719</guid>
		<description><![CDATA[The other day I wanted to experiment a bit with the JSON interface to AUR. Of course my first stop was at HackageDB to look for a Haskell package for parsing JSON. There are several of them, but only one that seemed suitable for some quick experimentation, especially I wanted to avoid pre-defining data types [...]]]></description>
			<content:encoded><![CDATA[<p>The other day I wanted to experiment a bit with the <a href="http://aur.archlinux.org/rpc.php">JSON interface to AUR</a>. Of course my first stop was at <a href="http://hackage.haskell.org/packages/hackage.html">HackageDB</a> to look for a Haskell package for parsing JSON.  There are several of them, but only <a href="http://hackage.haskell.org/package/json">one</a> that seemed suitable for some quick experimentation, especially I wanted to avoid pre-defining data types for the objects in the JSON interface.  That failed however and I ended up switching to Python.  It did bother me though, and later on, when I had some more time I decided to have another look at <a href="http://hackage.haskell.org/package/json">json</a>.  I was also helped by Don&#8217;s recent work on wrapping up the <a href="http://hackage.haskell.org/package/archlinux">AUR JSON interface in Haskell</a>.</p>

<p>After some searching online I found a reasonably good example<sup><a href="http://therning.org/magnus/archives/719#footnote_0_719" id="identifier_0_719" class="footnote-link footnote-identifier-link" title="it&amp;#8217;s a modified version of what I found here.">i</a></sup>:</p>

<pre><code>{ "ID": "SGML"
, "SortAs": "SGML"
, "GlossDef":
    { "para": "A meta-markup language, used to create markup languages such as DocBook."
    , "GlossSeeAlso": ["GML", "XML"]
    }
}
</code></pre>

<p>As a slight aside, the absolutely easiest way to add JSON to your program is to derive <code>Data</code> (and by implication <code>Typeable</code> too).  This is the way I might have represented the data above in Haskell<sup><a href="http://therning.org/magnus/archives/719#footnote_1_719" id="identifier_1_719" class="footnote-link footnote-identifier-link" title="The file should include {-# LANGUAGE DeriveDataTypeable #-} and both Data.Typeable and Data.Data must be imported.">ii</a></sup> :</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">data</span> GlossDef <span style="color: #339933; font-weight: bold;">=</span> GlossDef
    <span style="color: green;">&#123;</span> glossDefPara <span style="color: #339933; font-weight: bold;">::</span> <span style="color: #cccc00; font-weight: bold;">String</span>
    <span style="color: #339933; font-weight: bold;">,</span> glossDefSeeAlso <span style="color: #339933; font-weight: bold;">::</span> <span style="color: green;">&#91;</span><span style="color: #cccc00; font-weight: bold;">String</span><span style="color: green;">&#93;</span>
    <span style="color: green;">&#125;</span> <span style="color: #06c; font-weight: bold;">deriving</span> <span style="color: green;">&#40;</span><span style="color: #cccc00; font-weight: bold;">Eq</span><span style="color: #339933; font-weight: bold;">,</span> <span style="color: #cccc00; font-weight: bold;">Show</span><span style="color: #339933; font-weight: bold;">,</span> Typeable<span style="color: #339933; font-weight: bold;">,</span> Data<span style="color: green;">&#41;</span> 
&nbsp;
<span style="color: #06c; font-weight: bold;">data</span> GlossEntry <span style="color: #339933; font-weight: bold;">=</span> GlossEntry
    <span style="color: green;">&#123;</span> glossEntryId <span style="color: #339933; font-weight: bold;">::</span> <span style="color: #cccc00; font-weight: bold;">String</span>
    <span style="color: #339933; font-weight: bold;">,</span> glossEntrySortAs <span style="color: #339933; font-weight: bold;">::</span> <span style="color: #cccc00; font-weight: bold;">String</span>
    <span style="color: #339933; font-weight: bold;">,</span> glossEntryGlossDef <span style="color: #339933; font-weight: bold;">::</span> GlossDef
    <span style="color: green;">&#125;</span> <span style="color: #06c; font-weight: bold;">deriving</span> <span style="color: green;">&#40;</span><span style="color: #cccc00; font-weight: bold;">Eq</span><span style="color: #339933; font-weight: bold;">,</span> <span style="color: #cccc00; font-weight: bold;">Show</span><span style="color: #339933; font-weight: bold;">,</span> Typeable<span style="color: #339933; font-weight: bold;">,</span> Data<span style="color: green;">&#41;</span></pre></div></div>


<p>After that it&#8217;s as easy as using <code>Text.JSON.Generic.toJSON</code> followed by <code>Text.JSON.encode</code>:</p>

<pre><code>&gt; let gd = GlossDef "foo" ["bar", "baz"]
&gt; let ge = GlossEntry "aa" "bb" gd
&gt; putStrLn $ encode $ toJSON ge
{"glossEntryId":"aa","glossEntrySortAs":"bb","glossEntryGlossDef":{"glossDefPara":"foo","glossDefSeeAlso":["bar","baz"]}}
</code></pre>

<p>As can be seen the &#8220;names&#8221; of the members are derived from the field names in the datatypes.  Great for when you are designing new JSON objects, not when you are writing code to parse an already existing object.  For that there is another, more verbose way to do it.</p>

<p>Start with the same data types, but without deriving <code>Typeable</code> and <code>Data</code>:</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">data</span> GlossDef <span style="color: #339933; font-weight: bold;">=</span> GlossDef
    <span style="color: green;">&#123;</span> glossDefPara <span style="color: #339933; font-weight: bold;">::</span> <span style="color: #cccc00; font-weight: bold;">String</span>
    <span style="color: #339933; font-weight: bold;">,</span> glossDefSeeAlso <span style="color: #339933; font-weight: bold;">::</span> <span style="color: green;">&#91;</span><span style="color: #cccc00; font-weight: bold;">String</span><span style="color: green;">&#93;</span>
    <span style="color: green;">&#125;</span> <span style="color: #06c; font-weight: bold;">deriving</span> <span style="color: green;">&#40;</span><span style="color: #cccc00; font-weight: bold;">Eq</span><span style="color: #339933; font-weight: bold;">,</span> <span style="color: #cccc00; font-weight: bold;">Show</span><span style="color: green;">&#41;</span>
&nbsp;
<span style="color: #06c; font-weight: bold;">data</span> GlossEntry <span style="color: #339933; font-weight: bold;">=</span> GlossEntry
    <span style="color: green;">&#123;</span> glossEntryId <span style="color: #339933; font-weight: bold;">::</span> <span style="color: #cccc00; font-weight: bold;">String</span>
    <span style="color: #339933; font-weight: bold;">,</span> glossEntrySortAs <span style="color: #339933; font-weight: bold;">::</span> <span style="color: #cccc00; font-weight: bold;">String</span>
    <span style="color: #339933; font-weight: bold;">,</span> glossEntryGlossDef <span style="color: #339933; font-weight: bold;">::</span> GlossDef
    <span style="color: green;">&#125;</span> <span style="color: #06c; font-weight: bold;">deriving</span> <span style="color: green;">&#40;</span><span style="color: #cccc00; font-weight: bold;">Eq</span><span style="color: #339933; font-weight: bold;">,</span> <span style="color: #cccc00; font-weight: bold;">Show</span><span style="color: green;">&#41;</span></pre></div></div>


<p>Then you have to implement <code>Text.JSON.JSON</code>.  Only two of the four functions must be implemented, <code>showJSON</code> and <code>readJSON</code>.  Starting with
<code>GlossDef</code>:</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">instance</span> JSON GlossDef <span style="color: #06c; font-weight: bold;">where</span>
    showJSON gd <span style="color: #339933; font-weight: bold;">=</span> makeObj
        <span style="color: green;">&#91;</span> <span style="color: green;">&#40;</span><span style="background-color: #3cb371;">&quot;para&quot;</span><span style="color: #339933; font-weight: bold;">,</span> showJSON <span style="color: #339933; font-weight: bold;">$</span> glossDefPara gd<span style="color: green;">&#41;</span>
        <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="background-color: #3cb371;">&quot;GlossSeeAlso&quot;</span><span style="color: #339933; font-weight: bold;">,</span> showJSON <span style="color: #339933; font-weight: bold;">$</span> glossDefSeeAlso gd<span style="color: green;">&#41;</span>
        <span style="color: green;">&#93;</span></pre></div></div>


<p>Basically this part defers to the already supplied implementations for the fields&#8217; types.  The same approach works for <code>readJSON</code> too:</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">    readJSON <span style="color: green;">&#40;</span>JSObject obj<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">let</span>
            jsonObjAssoc <span style="color: #339933; font-weight: bold;">=</span> fromJSObject obj
        <span style="color: #06c; font-weight: bold;">in</span> <span style="color: #06c; font-weight: bold;">do</span>
            para <span style="color: #339933; font-weight: bold;">&lt;-</span> mLookup <span style="background-color: #3cb371;">&quot;para&quot;</span> jsonObjAssoc <span style="color: #339933; font-weight: bold;">&gt;&gt;=</span> readJSON
            seeAlso <span style="color: #339933; font-weight: bold;">&lt;-</span> mLookup <span style="background-color: #3cb371;">&quot;GlossSeeAlso&quot;</span> jsonObjAssoc <span style="color: #339933; font-weight: bold;">&gt;&gt;=</span> readJSON
            <span style="font-weight: bold;">return</span> <span style="color: #339933; font-weight: bold;">$</span> GlossDef
                <span style="color: green;">&#123;</span> glossDefPara <span style="color: #339933; font-weight: bold;">=</span> para
                <span style="color: #339933; font-weight: bold;">,</span> glossDefSeeAlso <span style="color: #339933; font-weight: bold;">=</span> seeAlso
                <span style="color: green;">&#125;</span>
&nbsp;
    readJSON <span style="color: #339933; font-weight: bold;">_</span> <span style="color: #339933; font-weight: bold;">=</span> <span style="font-weight: bold;">fail</span> <span style="background-color: #3cb371;">&quot;&quot;</span></pre></div></div>


<p>The function <code>mLookup</code> is a wrapper around <code>lookup</code> that makes it a bit nicer to work with in monads other than <code>Maybe</code>:</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">mLookup a <span style="color: #06c; font-weight: bold;">as</span> <span style="color: #339933; font-weight: bold;">=</span> <span style="font-weight: bold;">maybe</span> <span style="color: green;">&#40;</span><span style="font-weight: bold;">fail</span> <span style="color: #339933; font-weight: bold;">$</span> <span style="background-color: #3cb371;">&quot;No such element: &quot;</span> <span style="color: #339933; font-weight: bold;">++</span> a<span style="color: green;">&#41;</span> <span style="font-weight: bold;">return</span> <span style="color: green;">&#40;</span><span style="font-weight: bold;">lookup</span> a <span style="color: #06c; font-weight: bold;">as</span><span style="color: green;">&#41;</span></pre></div></div>


<p>(The choice to include the key in the string passed to <code>fail</code> limits the usefulness somewhat in the general case, but for this example it doesn&#8217;t make any difference.)</p>

<p>Implementing the interface for <code>GlossEntry</code> is analogous:</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">instance</span> JSON GlossEntry <span style="color: #06c; font-weight: bold;">where</span>
    showJSON ge <span style="color: #339933; font-weight: bold;">=</span> makeObj
        <span style="color: green;">&#91;</span> <span style="color: green;">&#40;</span><span style="background-color: #3cb371;">&quot;ID&quot;</span><span style="color: #339933; font-weight: bold;">,</span> showJSON <span style="color: #339933; font-weight: bold;">$</span> glossEntryId ge<span style="color: green;">&#41;</span>
        <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="background-color: #3cb371;">&quot;SortAs&quot;</span><span style="color: #339933; font-weight: bold;">,</span> showJSON <span style="color: #339933; font-weight: bold;">$</span> glossEntrySortAs ge<span style="color: green;">&#41;</span>
        <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="background-color: #3cb371;">&quot;GlossDef&quot;</span><span style="color: #339933; font-weight: bold;">,</span> showJSON <span style="color: #339933; font-weight: bold;">$</span> glossEntryGlossDef ge<span style="color: green;">&#41;</span>
        <span style="color: green;">&#93;</span>
&nbsp;
    readJSON <span style="color: green;">&#40;</span>JSObject obj<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">let</span>
            jsonObjAssoc <span style="color: #339933; font-weight: bold;">=</span> fromJSObject obj
        <span style="color: #06c; font-weight: bold;">in</span> <span style="color: #06c; font-weight: bold;">do</span>
            <span style="font-weight: bold;">id</span> <span style="color: #339933; font-weight: bold;">&lt;-</span> mLookup <span style="background-color: #3cb371;">&quot;ID&quot;</span> jsonObjAssoc <span style="color: #339933; font-weight: bold;">&gt;&gt;=</span> readJSON
            sortAs <span style="color: #339933; font-weight: bold;">&lt;-</span> mLookup <span style="background-color: #3cb371;">&quot;SortAs&quot;</span> jsonObjAssoc <span style="color: #339933; font-weight: bold;">&gt;&gt;=</span> readJSON
            gd <span style="color: #339933; font-weight: bold;">&lt;-</span> mLookup <span style="background-color: #3cb371;">&quot;GlossDef&quot;</span> jsonObjAssoc <span style="color: #339933; font-weight: bold;">&gt;&gt;=</span> readJSON
            <span style="font-weight: bold;">return</span> <span style="color: #339933; font-weight: bold;">$</span> GlossEntry
                <span style="color: green;">&#123;</span> glossEntryId <span style="color: #339933; font-weight: bold;">=</span> <span style="font-weight: bold;">id</span>
                <span style="color: #339933; font-weight: bold;">,</span> glossEntrySortAs <span style="color: #339933; font-weight: bold;">=</span> sortAs
                <span style="color: #339933; font-weight: bold;">,</span> glossEntryGlossDef <span style="color: #339933; font-weight: bold;">=</span> gd
                <span style="color: green;">&#125;</span></pre></div></div>


<p>With the JSON object mentioned at the top in the file <code>test.json</code> the following is possible:</p>

<pre><code>&gt; f &lt;- readFile "test.json"
&gt; let (Ok j) = decode f :: Result GlossEntry
&gt; putStrLn $ encode j
{"ID":"SGML","SortAs":"SGML","GlossDef":{"para":"A meta-markup language, used to create markup languages such as DocBook.","GlossSeeAlso":["GML","XML"]}}
</code></pre>

<p>I have a feeling the implemention of <code>readJSON</code> could be simplified by using an applicative style, but I leave that as an excercise for the reader <img src='http://therning.org/magnus/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<ol class="footnotes"><li id="footnote_0_719" class="footnote">it&#8217;s a modified version of what I found <a href="http://www.json.org/example.html">here</a>.</li><li id="footnote_1_719" class="footnote">The file should include <code>{-# LANGUAGE DeriveDataTypeable #-}</code> and both <code>Data.Typeable</code> and <code>Data.Data</code> must be imported.</li></ol><p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Bookmark</a> </p>]]></content:encoded>
			<wfw:commentRss>http://therning.org/magnus/archives/719/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Updating GHC on Arch</title>
		<link>http://therning.org/magnus/archives/713</link>
		<comments>http://therning.org/magnus/archives/713#comments</comments>
		<pubDate>Tue, 04 Aug 2009 21:41:07 +0000</pubDate>
		<dc:creator>Magnus</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[arch]]></category>
		<category><![CDATA[ghc]]></category>
		<category><![CDATA[haskell]]></category>

		<guid isPermaLink="false">http://therning.org/magnus/?p=713</guid>
		<description><![CDATA[Arch is somewhat of a hybrid distribution in the sense that if you have any sort of &#8216;peculiar&#8217; needs then you are likely to have to build packages from source. As expected developing in Haskell is a &#8220;peculiar need&#8221; After every upgrade of GHC I find myself in the situation where the system (pacman) and [...]]]></description>
			<content:encoded><![CDATA[<p>Arch is somewhat of a hybrid distribution in the sense that if you have any
sort of &#8216;peculiar&#8217; needs then you are likely to have to build packages from
source.  As expected developing in Haskell is a &#8220;peculiar need&#8221; <img src='http://therning.org/magnus/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>

<p>After every upgrade of GHC I find myself in the situation where the system
(pacman) and GHC have different views of what packages are available.  What is
needed then is somehow finding out the difference, and this is how I found
that difference after the recent 6.10.3 -> 6.10.4 upgrade of GHC.  Once I know
what packages are missing from GHC&#8217;s view of the world I can use <code>pacman</code> to
first remove and then <code>yaourt</code> to rebuild the packages.</p>

<p>First I noted that the old <code>package.conf</code> file wasn&#8217;t deleted during the
upgrade, apparently <code>pacman</code> noted the changes that installing packages
resulted in and saved the file as <code>package.conf.pacsave</code>.  Finding the name of
all the &#8216;missing&#8217; packages was then as simple as loading both
<code>/usr/lib/ghc-6.10.3/package.conf.pacsave</code> and
<code>/usr/lib/ghc-6.10.4/package.conf</code>, filter out the package names and take the
difference:</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">printMissingPackages <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">let</span>
        pkgNameStr <span style="color: #339933; font-weight: bold;">=</span> PackageName <span style="color: #339933; font-weight: bold;">.</span> display <span style="color: #339933; font-weight: bold;">.</span> packageName
    <span style="color: #06c; font-weight: bold;">in</span> <span style="color: #06c; font-weight: bold;">do</span>
        oldPackConf <span style="color: #339933; font-weight: bold;">&lt;-</span> <span style="font-weight: bold;">readFile</span> <span style="background-color: #3cb371;">&quot;/usr/lib/ghc-6.10.3/package.conf.pacsave&quot;</span>
        curPackConf <span style="color: #339933; font-weight: bold;">&lt;-</span> <span style="font-weight: bold;">readFile</span> <span style="background-color: #3cb371;">&quot;/usr/lib/ghc-6.10.4/package.conf&quot;</span>
        <span style="color: #06c; font-weight: bold;">let</span> oldPacks <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#40;</span><span style="font-weight: bold;">read</span> oldPackConf<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">::</span> <span style="color: green;">&#91;</span>InstalledPackageInfo<span style="color: #339933; font-weight: bold;">_</span> <span style="color: #cccc00; font-weight: bold;">String</span><span style="color: green;">&#93;</span>
        <span style="color: #06c; font-weight: bold;">let</span> curPacks <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#40;</span><span style="font-weight: bold;">read</span> curPackConf<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">::</span> <span style="color: green;">&#91;</span>InstalledPackageInfo<span style="color: #339933; font-weight: bold;">_</span> <span style="color: #cccc00; font-weight: bold;">String</span><span style="color: green;">&#93;</span>
        <span style="color: #06c; font-weight: bold;">let</span> gonePacks <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#40;</span><span style="font-weight: bold;">map</span> pkgNameStr oldPacks<span style="color: green;">&#41;</span> \\ <span style="color: green;">&#40;</span><span style="font-weight: bold;">map</span> pkgNameStr curPacks<span style="color: green;">&#41;</span>
        <span style="font-weight: bold;">putStrLn</span> <span style="background-color: #3cb371;">&quot;Missing packages:&quot;</span>
        <span style="font-weight: bold;">mapM_</span> <span style="color: green;">&#40;</span><span style="font-weight: bold;">putStrLn</span> <span style="color: #339933; font-weight: bold;">.</span> display<span style="color: green;">&#41;</span> gonePacks</pre></div></div>


<p>That isn&#8217;t the most useful output however, so I decided to modify it to print
out the name of the Arch package that needed re-compilation.  The following
functions generates the name of the <code>.hi</code> of the first module in the Haskell
package, it then uses <code>pacman</code> to look up the owner of the file:</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">ghcPkg2ArchPkg pkg <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">let</span>
        hsFileLoc <span style="color: #339933; font-weight: bold;">=</span> <span style="font-weight: bold;">head</span> <span style="color: #339933; font-weight: bold;">$</span> libraryDirs pkg
        hsFile <span style="color: #339933; font-weight: bold;">=</span> <span style="font-weight: bold;">map</span> <span style="color: green;">&#40;</span>\ c <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: #06c; font-weight: bold;">if</span> c <span style="color: #339933; font-weight: bold;">==</span> '<span style="color: #339933; font-weight: bold;">.</span>' <span style="color: #06c; font-weight: bold;">then</span> '<span style="color: #339933; font-weight: bold;">/</span>' <span style="color: #06c; font-weight: bold;">else</span> c<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">$</span> <span style="font-weight: bold;">head</span> <span style="color: #339933; font-weight: bold;">$</span> exposedModules pkg
        hsFullFile <span style="color: #339933; font-weight: bold;">=</span> hsFileLoc <span style="color: #339933; font-weight: bold;">&lt;/&gt;</span> hsFile <span style="color: #339933; font-weight: bold;">&lt;.&gt;</span> <span style="background-color: #3cb371;">&quot;hi&quot;</span>
    <span style="color: #06c; font-weight: bold;">in</span> <span style="color: #06c; font-weight: bold;">do</span>
        exists <span style="color: #339933; font-weight: bold;">&lt;-</span> doesDirectoryExist hsFullFile
        <span style="color: #06c; font-weight: bold;">if</span> exists
            <span style="color: #06c; font-weight: bold;">then</span> liftM Just <span style="color: #339933; font-weight: bold;">$</span> archOwnerOfFile hsFullFile
            <span style="color: #06c; font-weight: bold;">else</span> <span style="font-weight: bold;">return</span> Nothing
&nbsp;
archOwnerOfFile fn <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">let</span>
        pkgFromPacmanOutput <span style="color: #339933; font-weight: bold;">=</span> <span style="font-weight: bold;">head</span> <span style="color: #339933; font-weight: bold;">.</span> <span style="font-weight: bold;">tail</span> <span style="color: #339933; font-weight: bold;">.</span> <span style="font-weight: bold;">reverse</span> <span style="color: #339933; font-weight: bold;">.</span> <span style="font-weight: bold;">words</span>
    <span style="color: #06c; font-weight: bold;">in</span> <span style="color: #06c; font-weight: bold;">do</span>
        res <span style="color: #339933; font-weight: bold;">&lt;-</span> rawSystemStdout silent <span style="background-color: #3cb371;">&quot;/usr/bin/pacman&quot;</span> <span style="color: green;">&#91;</span><span style="background-color: #3cb371;">&quot;-Qo&quot;</span><span style="color: #339933; font-weight: bold;">,</span> fn<span style="color: green;">&#93;</span>
        <span style="font-weight: bold;">return</span> <span style="color: #339933; font-weight: bold;">$</span> pkgFromPacmanOutput res</pre></div></div>


<p>Now I can find the list of Arch packages that aren&#8217;t known to the new version
of GHC by mapping <code>ghcPkg2ArchPkg</code> over <code>gonePkgs</code>.  In other words that is
the list of packages that need to be removed, but that can be different from
the list of packages that needs to be rebuilt with <code>yaourt</code> (basically I only
want to tell it to build and install the &#8216;top-level&#8217; packages, i.e. packages
that aren&#8217;t dependencies of any other packages.  It&#8217;s of course possible to
build that second list from the first one, with the help of <code>pacman</code>.</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">archGetRequiredBy pkg <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">let</span>
        extractPkgs pkgDesc <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">let</span>
                deps <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#40;</span><span style="font-weight: bold;">drop</span> <span style="color: red;">3</span> <span style="color: #339933; font-weight: bold;">.</span> <span style="font-weight: bold;">words</span> <span style="color: #339933; font-weight: bold;">.</span> <span style="font-weight: bold;">head</span> <span style="color: #339933; font-weight: bold;">.</span> <span style="font-weight: bold;">filter</span> <span style="color: green;">&#40;</span>isPrefixOf <span style="background-color: #3cb371;">&quot;Required By&quot;</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">.</span> <span style="font-weight: bold;">lines</span><span style="color: green;">&#41;</span> pkgDesc
            <span style="color: #06c; font-weight: bold;">in</span>
                <span style="color: #06c; font-weight: bold;">if</span> deps <span style="color: #339933; font-weight: bold;">==</span> <span style="color: green;">&#91;</span><span style="background-color: #3cb371;">&quot;None&quot;</span><span style="color: green;">&#93;</span>
                    <span style="color: #06c; font-weight: bold;">then</span> <span style="color: green;">&#91;</span><span style="color: green;">&#93;</span>
                    <span style="color: #06c; font-weight: bold;">else</span> deps
    <span style="color: #06c; font-weight: bold;">in</span> <span style="color: #06c; font-weight: bold;">do</span>
        res <span style="color: #339933; font-weight: bold;">&lt;-</span> rawSystemStdout silent <span style="background-color: #3cb371;">&quot;/usr/bin/pacman&quot;</span> <span style="color: green;">&#91;</span><span style="background-color: #3cb371;">&quot;-Qi&quot;</span><span style="color: #339933; font-weight: bold;">,</span> pkg<span style="color: green;">&#93;</span>
        <span style="font-weight: bold;">return</span> <span style="color: #339933; font-weight: bold;">$</span> extractPkgs res</pre></div></div>


<p>Now I can modify <code>printMissingPackages</code> to print some more useful information.
This is the full function:</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">printMissingPackages <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">let</span>
        pkgNameStr <span style="color: #339933; font-weight: bold;">=</span> PackageName <span style="color: #339933; font-weight: bold;">.</span> display <span style="color: #339933; font-weight: bold;">.</span> packageName
    <span style="color: #06c; font-weight: bold;">in</span> <span style="color: #06c; font-weight: bold;">do</span>
        oldPackConf <span style="color: #339933; font-weight: bold;">&lt;-</span> <span style="font-weight: bold;">readFile</span> <span style="background-color: #3cb371;">&quot;/usr/lib/ghc-6.10.3/package.conf.pacsave&quot;</span>
        curPackConf <span style="color: #339933; font-weight: bold;">&lt;-</span> <span style="font-weight: bold;">readFile</span> <span style="background-color: #3cb371;">&quot;/usr/lib/ghc-6.10.4/package.conf&quot;</span>
        <span style="color: #06c; font-weight: bold;">let</span> oldPacks <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#40;</span><span style="font-weight: bold;">read</span> oldPackConf<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">::</span> <span style="color: green;">&#91;</span>InstalledPackageInfo<span style="color: #339933; font-weight: bold;">_</span> <span style="color: #cccc00; font-weight: bold;">String</span><span style="color: green;">&#93;</span>
        <span style="color: #06c; font-weight: bold;">let</span> curPacks <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#40;</span><span style="font-weight: bold;">read</span> curPackConf<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">::</span> <span style="color: green;">&#91;</span>InstalledPackageInfo<span style="color: #339933; font-weight: bold;">_</span> <span style="color: #cccc00; font-weight: bold;">String</span><span style="color: green;">&#93;</span>
        <span style="color: #06c; font-weight: bold;">let</span> gonePacks <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#40;</span><span style="font-weight: bold;">map</span> pkgNameStr oldPacks<span style="color: green;">&#41;</span> \\ <span style="color: green;">&#40;</span><span style="font-weight: bold;">map</span> pkgNameStr curPacks<span style="color: green;">&#41;</span>
        <span style="font-weight: bold;">putStrLn</span> <span style="background-color: #3cb371;">&quot;Missing packages:&quot;</span>
        <span style="font-weight: bold;">mapM_</span> <span style="color: green;">&#40;</span><span style="font-weight: bold;">putStrLn</span> <span style="color: #339933; font-weight: bold;">.</span> display<span style="color: green;">&#41;</span> gonePackprints
        <span style="color: #06c; font-weight: bold;">let</span> gonePkgs <span style="color: #339933; font-weight: bold;">=</span> <span style="font-weight: bold;">filter</span> <span style="color: green;">&#40;</span>\ p <span style="color: #339933; font-weight: bold;">-&gt;</span> pkgNameStr p `<span style="font-weight: bold;">elem</span>` gonePacks<span style="color: green;">&#41;</span> oldPacks
        archPkgs <span style="color: #339933; font-weight: bold;">&lt;-</span> liftM catMaybes <span style="color: #339933; font-weight: bold;">$</span> <span style="font-weight: bold;">mapM</span> ghcPkg2ArchPkg gonePkgs
        <span style="font-weight: bold;">putStrLn</span> <span style="background-color: #3cb371;">&quot;Packages to remove:&quot;</span>
        <span style="font-weight: bold;">mapM_</span> <span style="font-weight: bold;">putStrLn</span> archPkgs
        archTopPkgs <span style="color: #339933; font-weight: bold;">&lt;-</span> filterM <span style="color: green;">&#40;</span>liftM <span style="color: green;">&#40;</span><span style="color: green;">&#91;</span><span style="color: green;">&#93;</span> <span style="color: #339933; font-weight: bold;">==</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">.</span> archGetRequiredBy<span style="color: green;">&#41;</span> archPkgs
        <span style="font-weight: bold;">putStrLn</span> <span style="background-color: #3cb371;">&quot;<span style="background-color: #3cb371; font-weight: bold;">\n</span>Packages to install:&quot;</span>
        <span style="font-weight: bold;">mapM_</span> <span style="font-weight: bold;">putStrLn</span> archTopPkgs</pre></div></div>


<p>On my system it produced the following output:</p>

<pre><code>Missing packages:
terminfo
vty
wl-pprint

Packages to remove:
haskell-terminfo
haskell-vty
haskell-wl-pprint

Packages to install:
haskell-vty
haskell-wl-pprint
</code></pre>

<p>And after a quick <code>pacman -Rn ...</code> and a not so quick <code>yaourt -S ...</code> I reran
it and the output was</p>

<pre><code>Packages to remove:

Packages to install:
</code></pre>

<p>Exactly as expected.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Bookmark</a> </p>]]></content:encoded>
			<wfw:commentRss>http://therning.org/magnus/archives/713/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Making a choice from a list in Haskell, Vty (part 4)</title>
		<link>http://therning.org/magnus/archives/710</link>
		<comments>http://therning.org/magnus/archives/710#comments</comments>
		<pubDate>Fri, 31 Jul 2009 22:12:05 +0000</pubDate>
		<dc:creator>Magnus</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[vty]]></category>

		<guid isPermaLink="false">http://therning.org/magnus/?p=710</guid>
		<description><![CDATA[After part 3 in this series, which might have been the longest post I&#8217;ve ever put on this blog, follows a much short post. In fact it&#8217;s so short it&#8217;s rather silly. In this post I&#8217;ll modify the Option type to render into multiple lines; two in fact (it&#8217;s easy to see that it would [...]]]></description>
			<content:encoded><![CDATA[<p>After <a href="http://therning.org/magnus/archives/702">part 3 in this series</a>, which might have been the longest post I&#8217;ve
ever put on this blog, follows a much short post.  In fact it&#8217;s so short it&#8217;s
rather silly.</p>

<p>In this post I&#8217;ll modify the <code>Option</code> type to render into multiple lines; two
in fact (it&#8217;s easy to see that it would work with more lines).</p>

<p>So, to start off, I add a second string to <code>Option</code>:</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">data</span> Option <span style="color: #339933; font-weight: bold;">=</span> Option <span style="color: green;">&#123;</span> optionRange<span style="color: #339933; font-weight: bold;">::</span><span style="color: green;">&#40;</span><span style="color: #cccc00; font-weight: bold;">Int</span><span style="color: #339933; font-weight: bold;">,</span> <span style="color: #cccc00; font-weight: bold;">Int</span><span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> optionS1<span style="color: #339933; font-weight: bold;">::</span><span style="color: #cccc00; font-weight: bold;">String</span><span style="color: #339933; font-weight: bold;">,</span> optionS2<span style="color: #339933; font-weight: bold;">::</span><span style="color: #cccc00; font-weight: bold;">String</span> <span style="color: green;">&#125;</span>
    <span style="color: #06c; font-weight: bold;">deriving</span> <span style="color: green;">&#40;</span><span style="color: #cccc00; font-weight: bold;">Show</span><span style="color: green;">&#41;</span></pre></div></div>


<p>Next the definition for <code>Pretty</code> is changed to render an <code>Option</code> on two
lines:</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">instance</span> Pretty Option <span style="color: #06c; font-weight: bold;">where</span>
    pretty <span style="color: green;">&#40;</span>Option <span style="color: #339933; font-weight: bold;">_</span> s1 s2<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> string s1 <span style="color: #339933; font-weight: bold;">&lt;&gt;</span> line <span style="color: #339933; font-weight: bold;">&lt;&gt;</span> indent <span style="color: red;">2</span> <span style="color: green;">&#40;</span>string s2<span style="color: green;">&#41;</span></pre></div></div>


<p>Due to the change to <code>Option</code> I also need to modify <code>optionIsInRange</code>:</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">optionIsInRange <span style="color: green;">&#40;</span>Option <span style="color: green;">&#40;</span>b<span style="color: #339933; font-weight: bold;">,</span> e<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">_</span> <span style="color: #339933; font-weight: bold;">_</span><span style="color: green;">&#41;</span> i <span style="color: #339933; font-weight: bold;">=</span> b <span style="color: #339933; font-weight: bold;">&lt;=</span> i <span style="color: #339933; font-weight: bold;">&amp;&amp;</span> i <span style="color: #339933; font-weight: bold;">&lt;=</span> e</pre></div></div>


<p>Finally the <code>options</code> need to be modified as well:</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">options <span style="color: #339933; font-weight: bold;">=</span> ozFromListWithMod <span style="color: green;">&#40;</span>optionSetRange <span style="color: red;">0</span><span style="color: green;">&#41;</span> <span style="color: green;">&#91;</span>Option <span style="color: green;">&#40;</span><span style="color: red;">0</span><span style="color: #339933; font-weight: bold;">,</span> <span style="color: red;">0</span><span style="color: green;">&#41;</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span><span style="font-weight: bold;">show</span> i<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">++</span> <span style="background-color: #3cb371;">&quot; Foo&quot;</span><span style="color: green;">&#41;</span> <span style="background-color: #3cb371;">&quot;Bar&quot;</span> <span style="color: #339933; font-weight: bold;">|</span> i <span style="color: #339933; font-weight: bold;">&lt;-</span> <span style="color: green;">&#91;</span>0<span style="color: #339933; font-weight: bold;">..</span>2<span style="color: green;">&#93;</span><span style="color: green;">&#93;</span></pre></div></div>


<p>That&#8217;s all there&#8217;s to it.  Short and sweet.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Bookmark</a> </p>]]></content:encoded>
			<wfw:commentRss>http://therning.org/magnus/archives/710/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Making a choice from a list in Haskell, Vty (part 3)</title>
		<link>http://therning.org/magnus/archives/702</link>
		<comments>http://therning.org/magnus/archives/702#comments</comments>
		<pubDate>Fri, 24 Jul 2009 08:36:54 +0000</pubDate>
		<dc:creator>Magnus</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[vty]]></category>
		<category><![CDATA[zipper]]></category>

		<guid isPermaLink="false">http://therning.org/magnus/?p=702</guid>
		<description><![CDATA[This is the third part, and it&#8217;s likely to be the longest one in the series. The three previous parts have been rather short, but now it&#8217;s time for a longer post because in this one I completely change the representation of the options that are rendered. Instead of using a list and an integer [...]]]></description>
			<content:encoded><![CDATA[<p>This is the third part, and it&#8217;s likely to be the longest one in the series.  The <a href="http://therning.org/magnus/archives/664">three</a> <a href="http://therning.org/magnus/archives/685">previous</a> <a href="http://therning.org/magnus/archives/689">parts</a> have been rather short, but now it&#8217;s time for a longer post because in this one I completely change the representation of the options that are rendered.</p>

<p>Instead of using a list and an integer I&#8217;ll use what is basically a zipper (with some extra fields for book keeping).  At the same time I also add a new field to the <code>Option</code> type to keep track of how many lines the option renders to.  At the moment it will always be one line, but the next part will actually make use of it.  (Yes, that part probably should have been kept in a separate part, but this happens to be how I wrote the code.)</p>

<p>First some changes to the <code>Option</code> type and its implementation of <code>Pretty</code>:</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">data</span> Option <span style="color: #339933; font-weight: bold;">=</span> Option <span style="color: green;">&#123;</span> optionRange<span style="color: #339933; font-weight: bold;">::</span><span style="color: green;">&#40;</span><span style="color: #cccc00; font-weight: bold;">Int</span><span style="color: #339933; font-weight: bold;">,</span> <span style="color: #cccc00; font-weight: bold;">Int</span><span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> optionS1<span style="color: #339933; font-weight: bold;">::</span><span style="color: #cccc00; font-weight: bold;">String</span> <span style="color: green;">&#125;</span>
    <span style="color: #06c; font-weight: bold;">deriving</span> <span style="color: green;">&#40;</span><span style="color: #cccc00; font-weight: bold;">Show</span><span style="color: green;">&#41;</span>
&nbsp;
<span style="color: #06c; font-weight: bold;">instance</span> Pretty Option <span style="color: #06c; font-weight: bold;">where</span>
    pretty <span style="color: green;">&#40;</span>Option <span style="color: #339933; font-weight: bold;">_</span> s<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> string s</pre></div></div>


<p>Then two functions related to the &#8220;range&#8221; of an <code>Option</code>.  The first to update based on a new start line (<em>n</em>ew <em>b</em>eginning), the second checks whether a line falls within the range of an <code>Option</code>:</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">optionSetRange nb o <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">let</span>
        l <span style="color: #339933; font-weight: bold;">=</span> <span style="font-weight: bold;">length</span> <span style="color: #339933; font-weight: bold;">$</span> <span style="font-weight: bold;">lines</span> <span style="color: #339933; font-weight: bold;">$</span> <span style="font-weight: bold;">show</span> <span style="color: #339933; font-weight: bold;">$</span> pretty o
    <span style="color: #06c; font-weight: bold;">in</span> o <span style="color: green;">&#123;</span> optionRange <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#40;</span>nb<span style="color: #339933; font-weight: bold;">,</span> nb <span style="color: #339933; font-weight: bold;">+</span> l <span style="color: #339933; font-weight: bold;">-</span> <span style="color: red;">1</span><span style="color: green;">&#41;</span> <span style="color: green;">&#125;</span>
&nbsp;
optionIsInRange <span style="color: green;">&#40;</span>Option <span style="color: green;">&#40;</span>b<span style="color: #339933; font-weight: bold;">,</span> e<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">_</span><span style="color: green;">&#41;</span> i <span style="color: #339933; font-weight: bold;">=</span> b <span style="color: #339933; font-weight: bold;">&lt;=</span> i <span style="color: #339933; font-weight: bold;">&amp;&amp;</span> i <span style="color: #339933; font-weight: bold;">&lt;=</span> e</pre></div></div>


<p>Now it&#8217;s time to introduce the zipper that replaces the list of options.  The basic idea is that there are two parts to a list, the left side (<code>ozLS</code>) and the right side (<code>ozRS</code>), and a current item.  In this list zipper the current item is the first item on the right side:</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">data</span> OptionZipper <span style="color: #339933; font-weight: bold;">=</span> OptionZipper <span style="color: green;">&#123;</span> ozIdx<span style="color: #339933; font-weight: bold;">::</span><span style="color: #cccc00; font-weight: bold;">Int</span><span style="color: #339933; font-weight: bold;">,</span> ozLS<span style="color: #339933; font-weight: bold;">::</span><span style="color: green;">&#91;</span>Option<span style="color: green;">&#93;</span><span style="color: #339933; font-weight: bold;">,</span> ozRS<span style="color: #339933; font-weight: bold;">::</span><span style="color: green;">&#91;</span>Option<span style="color: green;">&#93;</span>
<span style="color: green;">&#125;</span>
    <span style="color: #06c; font-weight: bold;">deriving</span> <span style="color: green;">&#40;</span><span style="color: #cccc00; font-weight: bold;">Show</span><span style="color: green;">&#41;</span></pre></div></div>


<p>Making the zipper an instance of <code>Pretty</code> is as simple as this:</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">instance</span> Pretty OptionZipper <span style="color: #06c; font-weight: bold;">where</span>
    pretty <span style="color: #339933; font-weight: bold;">=</span> vcat <span style="color: #339933; font-weight: bold;">.</span> <span style="font-weight: bold;">map</span> pretty <span style="color: #339933; font-weight: bold;">.</span> ozToList</pre></div></div>


<p>It&#8217;s useful to be able to both convert to and from lists (as seen just above in the <code>Pretty</code> instance):</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">ozFromList l <span style="color: #339933; font-weight: bold;">=</span> OptionZipper <span style="color: red;">0</span> <span style="color: green;">&#91;</span><span style="color: green;">&#93;</span> l
ozFromListWithMod f <span style="color: #339933; font-weight: bold;">=</span> ozCursorMod f <span style="color: #339933; font-weight: bold;">.</span> ozFromList
&nbsp;
ozToList <span style="color: green;">&#40;</span>OptionZipper <span style="color: #339933; font-weight: bold;">_</span> l r<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> <span style="font-weight: bold;">reverse</span> l <span style="color: #339933; font-weight: bold;">++</span> r</pre></div></div>


<p>The function for getting the current item is obvious.  At the same time I&#8217;ll define a function that applies a function to the item at the cursor.</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">ozCursor <span style="color: green;">&#40;</span>OptionZipper <span style="color: #339933; font-weight: bold;">_</span> <span style="color: #339933; font-weight: bold;">_</span> <span style="color: green;">&#40;</span>r:<span style="color: #339933; font-weight: bold;">_</span><span style="color: green;">&#41;</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> Just r
ozCursor <span style="color: #339933; font-weight: bold;">_</span> <span style="color: #339933; font-weight: bold;">=</span> Nothing
&nbsp;
ozCursorMod f o<span style="color: #339933; font-weight: bold;">@</span><span style="color: green;">&#40;</span>OptionZipper <span style="color: #339933; font-weight: bold;">_</span> <span style="color: #339933; font-weight: bold;">_</span> <span style="color: green;">&#40;</span>r:rs<span style="color: green;">&#41;</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> o <span style="color: green;">&#123;</span> ozRS <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#40;</span>f r:rs<span style="color: green;">&#41;</span> <span style="color: green;">&#125;</span>
ozCursorMod <span style="color: #339933; font-weight: bold;">_</span> o <span style="color: #339933; font-weight: bold;">=</span> o</pre></div></div>


<p>Usually a list zipper has functions to move the cursor, i.e. move items between the left and right sides.  In this zipper there is some extra bookkeeping that has to be done to make sure that the index is correct and that the current item has a correct range:</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">ozLeft <span style="color: green;">&#40;</span>OptionZipper <span style="color: #339933; font-weight: bold;">_</span> <span style="color: green;">&#40;</span>l:ls<span style="color: green;">&#41;</span> rs<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">let</span>
        <span style="color: green;">&#40;</span>newIdx<span style="color: #339933; font-weight: bold;">,</span> <span style="color: #339933; font-weight: bold;">_</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> optionRange l
    <span style="color: #06c; font-weight: bold;">in</span> OptionZipper newIdx ls <span style="color: green;">&#40;</span>l:rs<span style="color: green;">&#41;</span>
ozLeft o <span style="color: #339933; font-weight: bold;">=</span> o
&nbsp;
ozRight <span style="color: green;">&#40;</span>OptionZipper <span style="color: #339933; font-weight: bold;">_</span> ls <span style="color: green;">&#40;</span>r:rs<span style="color: green;">&#41;</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">let</span>
        <span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">_,</span> pe<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> optionRange r
    <span style="color: #06c; font-weight: bold;">in</span> ozCursorMod <span style="color: green;">&#40;</span>optionSetRange <span style="color: #339933; font-weight: bold;">$</span> pe <span style="color: #339933; font-weight: bold;">+</span> <span style="color: red;">1</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">$</span> OptionZipper <span style="color: green;">&#40;</span>pe <span style="color: #339933; font-weight: bold;">+</span> <span style="color: red;">1</span><span style="color: green;">&#41;</span> <span style="color: green;">&#40;</span>r:ls<span style="color: green;">&#41;</span> rs
ozRight o <span style="color: #339933; font-weight: bold;">=</span> o</pre></div></div>


<p>That&#8217;s all good and well, but what I <em>really</em> need is to be able to navigate based on lines.  Expressing that using <code>ozLeft</code> and <code>ozRight</code> is fairly straight forward.  Let&#8217;s start with shifting to the next line, <code>ozNextLine</code>, it has two cases, one general case and one when the cursor points to the last item:</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">ozNextLine o<span style="color: #339933; font-weight: bold;">@</span><span style="color: green;">&#40;</span>OptionZipper i <span style="color: #339933; font-weight: bold;">_</span> <span style="color: green;">&#91;</span>c<span style="color: green;">&#93;</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span>
    <span style="color: #06c; font-weight: bold;">if</span> optionIsInRange c <span style="color: green;">&#40;</span>i <span style="color: #339933; font-weight: bold;">+</span> <span style="color: red;">1</span><span style="color: green;">&#41;</span>
        <span style="color: #06c; font-weight: bold;">then</span> o <span style="color: green;">&#123;</span> ozIdx <span style="color: #339933; font-weight: bold;">=</span> i <span style="color: #339933; font-weight: bold;">+</span> <span style="color: red;">1</span> <span style="color: green;">&#125;</span>
        <span style="color: #06c; font-weight: bold;">else</span> o
ozNextLine o <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">let</span>
        c <span style="color: #339933; font-weight: bold;">=</span> fromJust <span style="color: #339933; font-weight: bold;">$</span> ozCursor o
        i <span style="color: #339933; font-weight: bold;">=</span> ozIdx o
    <span style="color: #06c; font-weight: bold;">in</span> <span style="color: #06c; font-weight: bold;">if</span> optionIsInRange c <span style="color: green;">&#40;</span>i <span style="color: #339933; font-weight: bold;">+</span> <span style="color: red;">1</span><span style="color: green;">&#41;</span>
        <span style="color: #06c; font-weight: bold;">then</span> o <span style="color: green;">&#123;</span> ozIdx <span style="color: #339933; font-weight: bold;">=</span> i <span style="color: #339933; font-weight: bold;">+</span> <span style="color: red;">1</span> <span style="color: green;">&#125;</span>
        <span style="color: #06c; font-weight: bold;">else</span> ozRight o</pre></div></div>


<p>Anyone who pays attention will realise that this definition of <code>ozNextLine</code> isn&#8217;t complete.  The zipper is capable of pointing to the empty spot after the last item (when <code>ozRS</code> is <code>[]</code>, as would be the case for an empty list turned into a zipper).  For this occasion that is all right, but this would need some attention when using this in a proper program.</p>

<p>The definition of <code>ozPreviousLine</code> also has two cases:</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">ozPreviousLine o<span style="color: #339933; font-weight: bold;">@</span><span style="color: green;">&#40;</span>OptionZipper <span style="color: red;">0</span> <span style="color: #339933; font-weight: bold;">_</span> <span style="color: #339933; font-weight: bold;">_</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> o
ozPreviousLine o <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">let</span>
        c <span style="color: #339933; font-weight: bold;">=</span> fromJust <span style="color: #339933; font-weight: bold;">$</span> ozCursor o
        i <span style="color: #339933; font-weight: bold;">=</span> ozIdx o
    <span style="color: #06c; font-weight: bold;">in</span> <span style="color: #06c; font-weight: bold;">if</span> optionIsInRange c <span style="color: green;">&#40;</span>i <span style="color: #339933; font-weight: bold;">-</span> <span style="color: red;">1</span><span style="color: green;">&#41;</span>
        <span style="color: #06c; font-weight: bold;">then</span> o <span style="color: green;">&#123;</span> ozIdx <span style="color: #339933; font-weight: bold;">=</span> i <span style="color: #339933; font-weight: bold;">-</span> <span style="color: red;">1</span> <span style="color: green;">&#125;</span>
        <span style="color: #06c; font-weight: bold;">else</span> ozLeft o</pre></div></div>


<p>Yes, this function also has some assumptions built into it, just like for <code>ozNextLine</code> it&#8217;s enough to just realise that for this exercise.</p>

<p>That&#8217;s it for the zipper, now it&#8217;s possible to create the options:</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">options <span style="color: #339933; font-weight: bold;">=</span> ozFromListWithMod <span style="color: green;">&#40;</span>optionSetRange <span style="color: red;">0</span><span style="color: green;">&#41;</span> <span style="color: green;">&#91;</span>Option <span style="color: green;">&#40;</span><span style="color: red;">0</span><span style="color: #339933; font-weight: bold;">,</span> <span style="color: red;">0</span><span style="color: green;">&#41;</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span><span style="font-weight: bold;">show</span> i<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">++</span> <span style="background-color: #3cb371;">&quot; Foo&quot;</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">|</span> i <span style="color: #339933; font-weight: bold;">&lt;-</span> <span style="color: green;">&#91;</span>0<span style="color: #339933; font-weight: bold;">..</span>99<span style="color: green;">&#93;</span><span style="color: green;">&#93;</span></pre></div></div>


<p>The introduction of the zipper requires large changes to both <code>getChoice</code> and <code>_getChoice</code>.  The changes are however very straight forward and in my opinion they make both functions easier to read and understand.  I&#8217;ll simply copy in the definitions without any comments in the hope that thanks to using a zipper the code is self-explanatory <img src='http://therning.org/magnus/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />   It might be worth pointing out though that <code>render</code> is still passed a list of strings to render, so it requires no changes
at this point.</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">getChoice vt opts <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">do</span>
    <span style="color: green;">&#40;</span>sx<span style="color: #339933; font-weight: bold;">,</span> sy<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">&lt;-</span> getSize vt
    <span style="color: #339933; font-weight: bold;">_</span>getChoice vt opts sx sy
&nbsp;
&nbsp;
<span style="color: #339933; font-weight: bold;">_</span>getChoice vt opts sx sy <span style="color: #339933; font-weight: bold;">=</span>
    <span style="color: #06c; font-weight: bold;">let</span>
        <span style="color: #339933; font-weight: bold;">_</span>converted<span style="color: #339933; font-weight: bold;">_</span>opts <span style="color: #339933; font-weight: bold;">=</span> <span style="font-weight: bold;">lines</span> <span style="color: #339933; font-weight: bold;">$</span> <span style="font-weight: bold;">show</span> <span style="color: #339933; font-weight: bold;">$</span> pretty opts
        <span style="color: #339933; font-weight: bold;">_</span>idx <span style="color: #339933; font-weight: bold;">=</span> ozIdx opts
        <span style="color: #339933; font-weight: bold;">_</span>calcTop winHeight listLength idx <span style="color: #339933; font-weight: bold;">=</span> <span style="font-weight: bold;">max</span> <span style="color: red;">0</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span><span style="font-weight: bold;">min</span> listLength <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span><span style="font-weight: bold;">max</span> <span style="color: red;">0</span> <span style="color: green;">&#40;</span>idx <span style="color: #339933; font-weight: bold;">-</span> winHeight `<span style="font-weight: bold;">div</span>` <span style="color: red;">2</span><span style="color: green;">&#41;</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">+</span> winHeight<span style="color: green;">&#41;</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">-</span> winHeight<span style="color: green;">&#41;</span>
        <span style="color: #339933; font-weight: bold;">_</span>top <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #339933; font-weight: bold;">_</span>calcTop sy <span style="color: green;">&#40;</span><span style="font-weight: bold;">length</span> <span style="color: #339933; font-weight: bold;">_</span>converted<span style="color: #339933; font-weight: bold;">_</span>opts<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">_</span>idx
        <span style="color: #339933; font-weight: bold;">_</span>visible<span style="color: #339933; font-weight: bold;">_</span>opts <span style="color: #339933; font-weight: bold;">=</span> <span style="font-weight: bold;">take</span> sy <span style="color: green;">&#40;</span><span style="font-weight: bold;">drop</span> <span style="color: #339933; font-weight: bold;">_</span>top <span style="color: #339933; font-weight: bold;">_</span>converted<span style="color: #339933; font-weight: bold;">_</span>opts<span style="color: green;">&#41;</span>
    <span style="color: #06c; font-weight: bold;">in</span> <span style="color: #06c; font-weight: bold;">do</span>
        update vt <span style="color: green;">&#40;</span>render <span style="color: #339933; font-weight: bold;">_</span>visible<span style="color: #339933; font-weight: bold;">_</span>opts <span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">_</span>idx <span style="color: #339933; font-weight: bold;">-</span> <span style="color: #339933; font-weight: bold;">_</span>top<span style="color: green;">&#41;</span> sx<span style="color: green;">&#41;</span>
        k <span style="color: #339933; font-weight: bold;">&lt;-</span> getEvent vt
        <span style="color: #06c; font-weight: bold;">case</span> k <span style="color: #06c; font-weight: bold;">of</span>
            EvKey KDown <span style="color: green;">&#91;</span><span style="color: green;">&#93;</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: #339933; font-weight: bold;">_</span>getChoice vt <span style="color: green;">&#40;</span>ozNextLine opts<span style="color: green;">&#41;</span> sx sy
            EvKey KUp <span style="color: green;">&#91;</span><span style="color: green;">&#93;</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: #339933; font-weight: bold;">_</span>getChoice vt <span style="color: green;">&#40;</span>ozPreviousLine opts<span style="color: green;">&#41;</span> sx sy
            EvKey KEsc <span style="color: green;">&#91;</span><span style="color: green;">&#93;</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> shutdown vt <span style="color: #339933; font-weight: bold;">&gt;&gt;</span> <span style="font-weight: bold;">return</span> Nothing
            EvKey KEnter <span style="color: green;">&#91;</span><span style="color: green;">&#93;</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> shutdown vt <span style="color: #339933; font-weight: bold;">&gt;&gt;</span> <span style="font-weight: bold;">return</span> <span style="color: green;">&#40;</span>Just <span style="color: #339933; font-weight: bold;">$</span> <span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">_</span>idx<span style="color: #339933; font-weight: bold;">,</span> ozCursor opts<span style="color: green;">&#41;</span><span style="color: green;">&#41;</span>
            EvResize nx ny <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: #339933; font-weight: bold;">_</span>getChoice vt opts nx ny
            <span style="color: #339933; font-weight: bold;">_</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: #339933; font-weight: bold;">_</span>getChoice vt opts sx sy</pre></div></div>

<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Bookmark</a> </p>]]></content:encoded>
			<wfw:commentRss>http://therning.org/magnus/archives/702/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Ping server in Haskell (not that kind of ping, and rather silly)</title>
		<link>http://therning.org/magnus/archives/698</link>
		<comments>http://therning.org/magnus/archives/698#comments</comments>
		<pubDate>Tue, 21 Jul 2009 10:03:18 +0000</pubDate>
		<dc:creator>Magnus</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[ping]]></category>

		<guid isPermaLink="false">http://therning.org/magnus/?p=698</guid>
		<description><![CDATA[Yesterday I needed to do some tests involving tunneling of network connections. Rather than firing up the full client-server setup that I want to tunnel I thought I&#8217;d use someting simple to test with first. Instead of looking online for a simple server to use, or hack one up using netcat, or even hack one [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday I needed to do some tests involving tunneling of network connections.  Rather than firing up the full client-server setup that I want to tunnel I thought I&#8217;d use someting simple to test with first.  Instead of looking online for a simple server to use, or hack one up using netcat, or even hack one in Python I decided to hack one in Haskell:</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">module</span> Main <span style="color: #06c; font-weight: bold;">where</span>
&nbsp;
<span style="color: #06c; font-weight: bold;">import</span> Control<span style="color: #339933; font-weight: bold;">.</span><span style="color: #cccc00; font-weight: bold;">Monad</span>
<span style="color: #06c; font-weight: bold;">import</span> System<span style="color: #339933; font-weight: bold;">.</span>Environment<span style="color: green;">&#40;</span>getArgs<span style="color: green;">&#41;</span>
<span style="color: #06c; font-weight: bold;">import</span> Network
<span style="color: #06c; font-weight: bold;">import</span> System<span style="color: #339933; font-weight: bold;">.</span><span style="color: #cccc00; font-weight: bold;">IO</span>
&nbsp;
main <span style="color: #339933; font-weight: bold;">=</span> withSocketsDo <span style="color: #339933; font-weight: bold;">$</span> <span style="color: #06c; font-weight: bold;">do</span>
    <span style="color: green;">&#91;</span>port<span style="color: #339933; font-weight: bold;">_</span>str<span style="color: green;">&#93;</span> <span style="color: #339933; font-weight: bold;">&lt;-</span> getArgs
    <span style="color: #06c; font-weight: bold;">let</span> port <span style="color: #339933; font-weight: bold;">=</span> <span style="font-weight: bold;">fromIntegral</span> <span style="color: green;">&#40;</span><span style="font-weight: bold;">read</span> port<span style="color: #339933; font-weight: bold;">_</span>str <span style="color: #339933; font-weight: bold;">::</span> <span style="color: #cccc00; font-weight: bold;">Int</span><span style="color: green;">&#41;</span>
    serv<span style="color: #339933; font-weight: bold;">_</span>sock <span style="color: #339933; font-weight: bold;">&lt;-</span> listenOn <span style="color: green;">&#40;</span>PortNumber port<span style="color: green;">&#41;</span>
    forever <span style="color: #339933; font-weight: bold;">$</span> <span style="color: #06c; font-weight: bold;">do</span>
        <span style="color: green;">&#40;</span>handle<span style="color: #339933; font-weight: bold;">,</span> host<span style="color: #339933; font-weight: bold;">,</span> port<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">&lt;-</span> accept serv<span style="color: #339933; font-weight: bold;">_</span>sock
        cmd <span style="color: #339933; font-weight: bold;">&lt;-</span> hGetLine handle
        when <span style="color: green;">&#40;</span>cmd <span style="color: #339933; font-weight: bold;">==</span> <span style="background-color: #3cb371;">&quot;Ping&quot;</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">$</span> hPutStr handle <span style="background-color: #3cb371;">&quot;Pong&quot;</span>
        hClose handle</pre></div></div>

<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Bookmark</a> </p>]]></content:encoded>
			<wfw:commentRss>http://therning.org/magnus/archives/698/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>XML prettifier in Haskell</title>
		<link>http://therning.org/magnus/archives/695</link>
		<comments>http://therning.org/magnus/archives/695#comments</comments>
		<pubDate>Tue, 14 Jul 2009 13:44:37 +0000</pubDate>
		<dc:creator>Magnus</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://therning.org/magnus/?p=695</guid>
		<description><![CDATA[I don&#8217;t know how many times I&#8217;ve gone looking for one of these but my search-fu is weak and I always give up, instead resorting to manual editing in Vim (no I hardly ever need the entire file to be pretty, only one or two tags that I&#8217;m interested in). Anyway, here&#8217;s a quick hack [...]]]></description>
			<content:encoded><![CDATA[<p>I don&#8217;t know how many times I&#8217;ve gone looking for one of these but my search-fu is weak and I always give up, instead resorting to manual editing in Vim (no I hardly ever need the <em>entire</em> file to be pretty, only one or two tags that I&#8217;m interested in).  Anyway, here&#8217;s a quick hack in Haskell, relying on <a href="http://hackage.haskell.org/package/xml">xml</a> for the heavy lifting:</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">#<span style="color: #339933; font-weight: bold;">!</span> <span style="color: #339933; font-weight: bold;">/</span>usr<span style="color: #339933; font-weight: bold;">/</span>bin<span style="color: #339933; font-weight: bold;">/</span>env runhaskell
&nbsp;
<span style="color: #06c; font-weight: bold;">module</span> Main <span style="color: #06c; font-weight: bold;">where</span>
&nbsp;
<span style="color: #06c; font-weight: bold;">import</span> Control<span style="color: #339933; font-weight: bold;">.</span><span style="color: #cccc00; font-weight: bold;">Monad</span>
<span style="color: #06c; font-weight: bold;">import</span> System<span style="color: #339933; font-weight: bold;">.</span>Environment
<span style="color: #06c; font-weight: bold;">import</span> Text<span style="color: #339933; font-weight: bold;">.</span>XML<span style="color: #339933; font-weight: bold;">.</span>Light<span style="color: #339933; font-weight: bold;">.</span>Input
<span style="color: #06c; font-weight: bold;">import</span> Text<span style="color: #339933; font-weight: bold;">.</span>XML<span style="color: #339933; font-weight: bold;">.</span>Light<span style="color: #339933; font-weight: bold;">.</span>Output
&nbsp;
main <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">do</span>
    fn <span style="color: #339933; font-weight: bold;">&lt;-</span> liftM <span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">!!</span> <span style="color: red;">0</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">$</span> getArgs
    xml<span style="color: #339933; font-weight: bold;">_</span>contents <span style="color: #339933; font-weight: bold;">&lt;-</span> <span style="font-weight: bold;">readFile</span> fn
    <span style="color: #06c; font-weight: bold;">let</span> <span style="color: green;">&#40;</span>Just doc<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> parseXMLDoc xml<span style="color: #339933; font-weight: bold;">_</span>contents
    <span style="font-weight: bold;">writeFile</span> <span style="color: green;">&#40;</span><span style="background-color: #3cb371;">&quot;pretty-&quot;</span> <span style="color: #339933; font-weight: bold;">++</span> fn<span style="color: green;">&#41;</span> <span style="color: green;">&#40;</span>ppTopElement doc<span style="color: green;">&#41;</span></pre></div></div>

<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Bookmark</a> </p>]]></content:encoded>
			<wfw:commentRss>http://therning.org/magnus/archives/695/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Making a choice from a list in Haskell, Vty (part 2)</title>
		<link>http://therning.org/magnus/archives/689</link>
		<comments>http://therning.org/magnus/archives/689#comments</comments>
		<pubDate>Thu, 09 Jul 2009 21:52:55 +0000</pubDate>
		<dc:creator>Magnus</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[vty]]></category>

		<guid isPermaLink="false">http://therning.org/magnus/?p=689</guid>
		<description><![CDATA[Following on the previous part is another baby step. This just changes the options from a list of strings to a list of objects (the only requirement that they implement Pretty): data Option = Option &#123; optionValue::String &#125; deriving &#40;Show&#41; &#160; instance Pretty Option where pretty &#40;Option s&#41; = string s After this it&#8217;s an [...]]]></description>
			<content:encoded><![CDATA[<p>Following on the <a href="http://therning.org/magnus/archives/685">previous part</a> is another baby step.  This just changes the options from a list of strings to a list of objects (the only requirement that they implement <code>Pretty</code>):</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">data</span> Option <span style="color: #339933; font-weight: bold;">=</span> Option <span style="color: green;">&#123;</span> optionValue<span style="color: #339933; font-weight: bold;">::</span><span style="color: #cccc00; font-weight: bold;">String</span> <span style="color: green;">&#125;</span>
    <span style="color: #06c; font-weight: bold;">deriving</span> <span style="color: green;">&#40;</span><span style="color: #cccc00; font-weight: bold;">Show</span><span style="color: green;">&#41;</span>
&nbsp;
<span style="color: #06c; font-weight: bold;">instance</span> Pretty Option <span style="color: #06c; font-weight: bold;">where</span>
    pretty <span style="color: green;">&#40;</span>Option s<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> string s</pre></div></div>


<p>After this it&#8217;s an easy step to replace the list of strings with a list of <code>Option</code>:</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">options <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#91;</span>Option <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span><span style="font-weight: bold;">show</span> i<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">++</span> <span style="background-color: #3cb371;">&quot; Foo&quot;</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">|</span> i <span style="color: #339933; font-weight: bold;">&lt;-</span> <span style="color: green;">&#91;</span>0<span style="color: #339933; font-weight: bold;">..</span>99<span style="color: green;">&#93;</span><span style="color: green;">&#93;</span></pre></div></div>


<p>That&#8217;s it!  Yes, yet another ridiculously short post, but I promise the next one will be considerably longer.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Bookmark</a> </p>]]></content:encoded>
			<wfw:commentRss>http://therning.org/magnus/archives/689/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Making a choice from a list in Haskell, Vty (part 1)</title>
		<link>http://therning.org/magnus/archives/685</link>
		<comments>http://therning.org/magnus/archives/685#comments</comments>
		<pubDate>Fri, 03 Jul 2009 09:46:07 +0000</pubDate>
		<dc:creator>Magnus</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[vty]]></category>

		<guid isPermaLink="false">http://therning.org/magnus/?p=685</guid>
		<description><![CDATA[After posting the zeroth part of this series I realised I hadn&#8217;t said anything about the final goal of this exercise. The first post contained code for choosing one one-line string (String) out of a list of one-line strings ([String]). What I really want is the ability to choose one item out of a list [...]]]></description>
			<content:encoded><![CDATA[<p>After posting the <a href="http://therning.org/magnus/archives/664">zeroth part</a> of this series I realised I hadn&#8217;t said
anything about the final goal of this exercise.  The first post contained code
for choosing one one-line string (<code>String</code>) out of a list of one-line strings
(<code>[String]</code>).  What I really want is the ability to choose one item out of a
list of items, where each may render to be multiple lines.  It would also be
really cool if an item could be collapsed and expanded in the rendering.
This is the first step in my journey towards these loosely specified
requriements.</p>

<p>Rendering items into strings sounds like pretty-printing to me, so I played
around a little with a few pretty-printing libraries.  Finally I settled on
the <a href="http://hackage.haskell.org/package/wl-pprint">Wadler/Leijen Pretty Printer</a> (<code>Text.PrettyPrint.Leijen</code>).  I didn&#8217;t
really have any strong reason for choosing it, beyond that it comes with its
own type class whereas the pretty-printing library that ships with GHC
(<code>Text.PrettyPrint.HughesPJ</code>) doesn&#8217;t (though there is a <a href="http://hackage.haskell.org/package/prettyclass">package on
HackageDB</a> with a class for it).</p>

<p>I did the smallest change I could think of to add pretty-printing.  First the
module needs to be imported of course:</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">import</span> Text<span style="color: #339933; font-weight: bold;">.</span>PrettyPrint<span style="color: #339933; font-weight: bold;">.</span>Leijen</pre></div></div>


<p>Then I added a function to turn a list of items into a document (<code>Doc</code>) where
each item is pretty-printed on its own line:</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">myPrettyList <span style="color: #339933; font-weight: bold;">::</span> Pretty a <span style="color: #339933; font-weight: bold;">=&gt;</span> <span style="color: green;">&#91;</span>a<span style="color: green;">&#93;</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> Doc
myPrettyList <span style="color: #339933; font-weight: bold;">=</span> vcat <span style="color: #339933; font-weight: bold;">.</span> <span style="font-weight: bold;">map</span> pretty</pre></div></div>


<p>I then decided that <code>_getChoice</code> should be left unchanged and instead modified
<code>getChoice</code> to turn the list of items into a list of strings:</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">getChoice vt opts <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">let</span>
        <span style="color: #339933; font-weight: bold;">_</span>converted<span style="color: #339933; font-weight: bold;">_</span>opts <span style="color: #339933; font-weight: bold;">=</span> myPrettyList opts
    <span style="color: #06c; font-weight: bold;">in</span> <span style="color: #06c; font-weight: bold;">do</span>
        <span style="color: green;">&#40;</span>sx<span style="color: #339933; font-weight: bold;">,</span> sy<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">&lt;-</span> getSize vt
        <span style="color: #339933; font-weight: bold;">_</span>getChoice vt <span style="color: green;">&#40;</span><span style="font-weight: bold;">lines</span> <span style="color: #339933; font-weight: bold;">$</span> <span style="font-weight: bold;">show</span> <span style="color: #339933; font-weight: bold;">_</span>converted<span style="color: #339933; font-weight: bold;">_</span>opts<span style="color: green;">&#41;</span> <span style="color: red;">0</span> sx sy</pre></div></div>


<p>That&#8217;s it.  The first step, albeit a small one.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Bookmark</a> </p>]]></content:encoded>
			<wfw:commentRss>http://therning.org/magnus/archives/685/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Setting up Epiphany to play with Seed extensions</title>
		<link>http://therning.org/magnus/archives/674</link>
		<comments>http://therning.org/magnus/archives/674#comments</comments>
		<pubDate>Fri, 03 Jul 2009 08:22:05 +0000</pubDate>
		<dc:creator>Magnus</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[epiphany]]></category>
		<category><![CDATA[gnome]]></category>
		<category><![CDATA[seed]]></category>

		<guid isPermaLink="false">http://therning.org/magnus/?p=674</guid>
		<description><![CDATA[Since the Python extensions to Epiphany have been removed from the repository I thought it was high time to start playing with what seems to be the replacement to Python extensions: Seed extensions. The first step is of course to get a version of Epiphany that supports Seed extensions. After a few emails on the [...]]]></description>
			<content:encoded><![CDATA[<p>Since the Python extensions to Epiphany have been removed from the repository I thought it was high time to start playing with what seems to be the replacement to Python extensions: <a href="http://live.gnome.org/Seed/">Seed</a> extensions.  The first step is of course to get a version of Epiphany that supports Seed extensions.  After a few emails on the mailing list I&#8217;ve come to a recipe (I&#8217;ve done this twice now on different machines to I&#8217;m fairly confident it works).  I should probably preface this by saying that I run an up-to-date <a href="http://www.archlinux.org/">Arch</a> system, if you run something else you might need to do a bit more, or less if you&#8217;re lucky <img src='http://therning.org/magnus/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>

<ol>
<li>Make sure the following packages are installed<sup><a href="http://therning.org/magnus/archives/674#footnote_0_674" id="identifier_0_674" class="footnote-link footnote-identifier-link" title="You might need a few more packages depending on what desktop environment you use.  Those were the packages I needed to add to my machine where I run Gnome and do regular non-Gnome development">i</a></sup>: <code>libsoup</code>, <code>libwebkit</code>, <code>gnome-common</code>, <code>intltool</code>, <code>libffi</code></li>
<li>Clone the following Git repositories from <a href="http://git.gnome.org/">git.gnome.org</a>: <code>epiphany-extensions</code>, <code>epiphany</code>, <code>seed</code>, <code>gobject-inspection</code>, <code>gnome-js-common</code>, <code>gir-repository</code></li>
<li><p>Decide on a <code>$prefix</code>, i.e. where you want it all installed (I use <code>~/opt/gnome-trunk</code>).  Then export the following environment variables:</p>

<pre><code>export PATH=$prefix/bin:$PATH
export PKG_CONFIG_PATH=$prefix/lib/pkgconfig
</code></pre></li>
<li><p>Then configure, build and install everything.  Use the <code>autogen.sh</code> script to create the configuration, and make sure to pass it <code>prefix=$prefix</code> each time.  Some of the modules need extra arguments as well.  This is the order and extra arguments I used:</p>

<ol>
<li><code>gnome-js-common</code> (<code>--disable-seed --disable-gjs</code>)</li>
<li><code>seed</code></li>
<li><code>gnome-js-common</code> (<code>--disable-gjs</code>)</li>
<li><code>gobject-introspection</code></li>
<li><code>gir-repository</code></li>
<li><code>epiphany</code> (<code>--enable-introspection --enable-seed</code>)</li>
<li><code>epiphany-extensions</code></li>
</ol></li>
</ol>

<p>After that you can put your extensions in <code>~/.gnome2/epiphany/extensions/</code>.  I have two instances of Epiphany installed, a stable from my distro, and the dev version I built myself.  I haven&#8217;t managed to run them both side by side, but beyond that there seems to be no bad interaction between them.</p>
<ol class="footnotes"><li id="footnote_0_674" class="footnote">You might need a few more packages depending on what desktop environment you use.  Those were the packages I needed to add to my machine where I run Gnome and do regular non-Gnome development</li></ol><p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Bookmark</a> </p>]]></content:encoded>
			<wfw:commentRss>http://therning.org/magnus/archives/674/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Dataenc finally making it into Debian</title>
		<link>http://therning.org/magnus/archives/672</link>
		<comments>http://therning.org/magnus/archives/672#comments</comments>
		<pubDate>Wed, 01 Jul 2009 13:54:59 +0000</pubDate>
		<dc:creator>Magnus</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[dataenc]]></category>
		<category><![CDATA[haskell]]></category>

		<guid isPermaLink="false">http://therning.org/magnus/?p=672</guid>
		<description><![CDATA[Erik de Castro Lopo is having a lot more success with getting dataenc into Debian than I ever had.]]></description>
			<content:encoded><![CDATA[<p>Erik de Castro Lopo is having a lot more success with getting <a href="http://www.mega-nerd.com/erikd/Blog/CodeHacking/Debian/polyparse_dataenc_json.html">dataenc into Debian</a> than I ever had.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Bookmark</a> </p>]]></content:encoded>
			<wfw:commentRss>http://therning.org/magnus/archives/672/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Making a choice from a list in Haskell, Vty (part 0)</title>
		<link>http://therning.org/magnus/archives/664</link>
		<comments>http://therning.org/magnus/archives/664#comments</comments>
		<pubDate>Sun, 28 Jun 2009 21:17:50 +0000</pubDate>
		<dc:creator>Magnus</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[vty]]></category>

		<guid isPermaLink="false">http://therning.org/magnus/?p=664</guid>
		<description><![CDATA[I haven&#8217;t had much free time lately, which means I haven&#8217;t written much non-work code. The only exception is some experiments with a small piece of Haskell code using the Vty module. Many moons ago I wrote a small piece of code that let&#8217;s the user choose options from a list in a terminal. Somewhat [...]]]></description>
			<content:encoded><![CDATA[<p>I haven&#8217;t had much free time lately, which means I haven&#8217;t written much
non-work code.  The only exception is some experiments with a small piece of
Haskell code using the <a href="http://hackage.haskell.org/package/vty">Vty</a> module.  Many moons ago I wrote a small piece
of code that let&#8217;s the user choose options from a list in a terminal.
Somewhat similar to what you get using <code>dialog --menu ...</code>, but of course a
lot more limited and less good looking.</p>

<p>Anyway, over the last few weeks I&#8217;ve slowly expanded it in a direction that
would be useful if I ever get around to work on yet another of those projects
that so far only exist in my head <img src='http://therning.org/magnus/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>

<p>I&#8217;ve kept the transformations in a stack of patches using <a href="http://savannah.nongnu.org/projects/quilt">quilt</a>, and I
thought I&#8217;d write a little about them.  Not because I think they are extremely useful or even
good in any way, but more because I really need to get back to writing some
blog posts <img src='http://therning.org/magnus/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>

<p>This is the zeroth post containing the version I put together when I first
came across <code>Vty</code>.  It is an executable program so it starts with the familiar</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">module</span> Main <span style="color: #06c; font-weight: bold;">where</span></pre></div></div>


<p>Next comes a few modules that have to be imported:</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">import</span> Data<span style="color: #339933; font-weight: bold;">.</span><span style="color: #cccc00; font-weight: bold;">Maybe</span>
<span style="color: #06c; font-weight: bold;">import</span> Graphics<span style="color: #339933; font-weight: bold;">.</span>Vty
<span style="color: #06c; font-weight: bold;">import</span> <span style="color: #06c; font-weight: bold;">qualified</span> Data<span style="color: #339933; font-weight: bold;">.</span>ByteString<span style="color: #339933; font-weight: bold;">.</span>Char8 <span style="color: #06c; font-weight: bold;">as</span> B</pre></div></div>


<p>The options are, in this version, represented as a list of strings.  For now
it&#8217;s enough to have a nonsensical list of unique strings.</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">options <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#91;</span> <span style="color: green;">&#40;</span><span style="font-weight: bold;">show</span> i<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">++</span> <span style="background-color: #3cb371;">&quot; Foo&quot;</span> <span style="color: #339933; font-weight: bold;">|</span> i <span style="color: #339933; font-weight: bold;">&lt;-</span> <span style="color: green;">&#91;</span>0<span style="color: #339933; font-weight: bold;">..</span>59<span style="color: green;">&#93;</span><span style="color: green;">&#93;</span></pre></div></div>


<p>The <code>main</code> function is as small as possible, two rows, the first creating an
instance of <code>Vty</code> and the second getting the choice and feeding it into
<code>print</code>.</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">main <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">do</span>
    vt <span style="color: #339933; font-weight: bold;">&lt;-</span> mkVty
    getChoice vt options <span style="color: #339933; font-weight: bold;">&gt;&gt;=</span> <span style="font-weight: bold;">print</span></pre></div></div>


<p>Of course one would think that <code>geChoice</code> would be the meat of the code, but
it is also short.  After getting the size of the terminal it calls
<code>_getChoice</code>, which <em>is</em> the meat of the code.  The reason for this split is
the handling of resize events.</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">getChoice vt opts <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">do</span>
    <span style="color: green;">&#40;</span>sx<span style="color: #339933; font-weight: bold;">,</span> sy<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">&lt;-</span> getSize vt
    <span style="color: #339933; font-weight: bold;">_</span>getChoice vt opts <span style="color: red;">0</span> sx sy</pre></div></div>


<p>The main part of <code>_getChoice</code> is straight forward, first update the terminal,
then wait for an event, and finally handle the event.  Unless the user wants
to exit (pressing enter choses an item, pressing escape exits without a
choice) a recursive call is made to <code>_getChoice</code> with slightly modified
arguments.</p>

<p>Probably the most complicated part is the calculation of the top of the list
of visible items.  The idea is that if the list has more items than there are
lines in the terminal then the <em>cursor</em> moves down until the middle line, once
there any down movement will result in the list scrolling up.  This continues
until the end of the list is visible, at that point the <em>cursor</em> moves down
towards the last line in the terminal.  I doubt that explanation makes sense,
hopefully it&#8217;ll be clear to anyone who bothers running the code.</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #339933; font-weight: bold;">_</span>getChoice vt opts idx sx sy <span style="color: #339933; font-weight: bold;">=</span>
    <span style="color: #06c; font-weight: bold;">let</span>
        <span style="color: #339933; font-weight: bold;">_</span>calcTop winHeight listLength idx <span style="color: #339933; font-weight: bold;">=</span> <span style="font-weight: bold;">max</span> <span style="color: red;">0</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span><span style="font-weight: bold;">min</span> listLength <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span><span style="font-weight: bold;">max</span> <span style="color: red;">0</span> <span style="color: green;">&#40;</span>idx <span style="color: #339933; font-weight: bold;">-</span> winHeight `<span style="font-weight: bold;">div</span>` <span style="color: red;">2</span><span style="color: green;">&#41;</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">+</span> winHeight<span style="color: green;">&#41;</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">-</span> winHeight<span style="color: green;">&#41;</span>
        <span style="color: #339933; font-weight: bold;">_</span>top <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #339933; font-weight: bold;">_</span>calcTop sy <span style="color: green;">&#40;</span><span style="font-weight: bold;">length</span> opts<span style="color: green;">&#41;</span> idx
        <span style="color: #339933; font-weight: bold;">_</span>visible<span style="color: #339933; font-weight: bold;">_</span>opts <span style="color: #339933; font-weight: bold;">=</span> <span style="font-weight: bold;">take</span> sy <span style="color: green;">&#40;</span><span style="font-weight: bold;">drop</span> <span style="color: #339933; font-weight: bold;">_</span>top opts<span style="color: green;">&#41;</span>
    <span style="color: #06c; font-weight: bold;">in</span> <span style="color: #06c; font-weight: bold;">do</span>
        update vt <span style="color: green;">&#40;</span>render <span style="color: #339933; font-weight: bold;">_</span>visible<span style="color: #339933; font-weight: bold;">_</span>opts <span style="color: green;">&#40;</span>idx <span style="color: #339933; font-weight: bold;">-</span> <span style="color: #339933; font-weight: bold;">_</span>top<span style="color: green;">&#41;</span> sx<span style="color: green;">&#41;</span>
        k <span style="color: #339933; font-weight: bold;">&lt;-</span> getEvent vt
        <span style="color: #06c; font-weight: bold;">case</span> k <span style="color: #06c; font-weight: bold;">of</span>
            EvKey KDown <span style="color: green;">&#91;</span><span style="color: green;">&#93;</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: #339933; font-weight: bold;">_</span>getChoice vt opts <span style="color: green;">&#40;</span><span style="font-weight: bold;">min</span> <span style="color: green;">&#40;</span><span style="font-weight: bold;">length</span> opts <span style="color: #339933; font-weight: bold;">-</span> <span style="color: red;">1</span><span style="color: green;">&#41;</span> <span style="color: green;">&#40;</span>idx <span style="color: #339933; font-weight: bold;">+</span> <span style="color: red;">1</span><span style="color: green;">&#41;</span><span style="color: green;">&#41;</span> sx sy
            EvKey KUp <span style="color: green;">&#91;</span><span style="color: green;">&#93;</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: #339933; font-weight: bold;">_</span>getChoice vt opts <span style="color: green;">&#40;</span><span style="font-weight: bold;">max</span> <span style="color: red;">0</span> <span style="color: green;">&#40;</span>idx <span style="color: #339933; font-weight: bold;">-</span> <span style="color: red;">1</span><span style="color: green;">&#41;</span><span style="color: green;">&#41;</span> sx sy
            EvKey KEsc <span style="color: green;">&#91;</span><span style="color: green;">&#93;</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> shutdown vt <span style="color: #339933; font-weight: bold;">&gt;&gt;</span> <span style="font-weight: bold;">return</span> Nothing
            EvKey KEnter <span style="color: green;">&#91;</span><span style="color: green;">&#93;</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> shutdown vt <span style="color: #339933; font-weight: bold;">&gt;&gt;</span> <span style="font-weight: bold;">return</span> <span style="color: green;">&#40;</span>Just <span style="color: #339933; font-weight: bold;">$</span> <span style="color: green;">&#40;</span>idx<span style="color: #339933; font-weight: bold;">,</span> opts <span style="color: #339933; font-weight: bold;">!!</span> idx<span style="color: green;">&#41;</span><span style="color: green;">&#41;</span>
            EvResize nx ny <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: #339933; font-weight: bold;">_</span>getChoice vt opts idx nx ny
            <span style="color: #339933; font-weight: bold;">_</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: #339933; font-weight: bold;">_</span>getChoice vt opts idx sx sy</pre></div></div>


<p>The final piece is the code that renders the list.  The items of the list are
zipped together with a list of integers.  Each such tuple is then rendered
into a line((The reason for the line rendering looking so complicated is that
<code>Vty</code> requires each line to be of equal lenght.)), where the line of the
cursor is highlighted.  The resulting list of rendered lines is then folded into
a full image.</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">render opts idx sx <span style="color: #339933; font-weight: bold;">=</span> pic <span style="color: green;">&#123;</span>
    pImage <span style="color: #339933; font-weight: bold;">=</span> <span style="font-weight: bold;">foldr1</span> <span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">&lt;-&gt;</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">$</span> <span style="font-weight: bold;">map</span> <span style="color: #339933; font-weight: bold;">_</span>render1 <span style="color: #339933; font-weight: bold;">$</span> <span style="font-weight: bold;">zip</span> <span style="color: green;">&#91;</span>0<span style="color: #339933; font-weight: bold;">..</span><span style="color: green;">&#93;</span> opts
    <span style="color: green;">&#125;</span>
    <span style="color: #06c; font-weight: bold;">where</span>
        <span style="color: #339933; font-weight: bold;">_</span>render1 <span style="color: green;">&#40;</span>i<span style="color: #339933; font-weight: bold;">,</span> o<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> renderHFill attr ' ' <span style="color: red;">5</span> <span style="color: #339933; font-weight: bold;">&lt;|&gt;</span> renderBS <span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">_</span>attr i<span style="color: green;">&#41;</span> <span style="color: green;">&#40;</span>B<span style="color: #339933; font-weight: bold;">.</span>pack o<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">&lt;|&gt;</span> renderHFill attr ' ' <span style="color: green;">&#40;</span>sx <span style="color: #339933; font-weight: bold;">-</span> <span style="color: red;">5</span> <span style="color: #339933; font-weight: bold;">-</span> <span style="font-weight: bold;">length</span> o<span style="color: green;">&#41;</span>
        <span style="color: #339933; font-weight: bold;">_</span>attr i <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">if</span> i <span style="color: #339933; font-weight: bold;">/=</span> idx
            <span style="color: #06c; font-weight: bold;">then</span> attr
            <span style="color: #06c; font-weight: bold;">else</span> setRV attr</pre></div></div>


<p>That&#8217;s it, that&#8217;s the starting point.  It&#8217;s also likely to be the longest post
in this planned series. <img src='http://therning.org/magnus/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Bookmark</a> </p>]]></content:encoded>
			<wfw:commentRss>http://therning.org/magnus/archives/664/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Using msmtp with darcs</title>
		<link>http://therning.org/magnus/archives/656</link>
		<comments>http://therning.org/magnus/archives/656#comments</comments>
		<pubDate>Tue, 09 Jun 2009 16:50:59 +0000</pubDate>
		<dc:creator>Magnus</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[darcs]]></category>
		<category><![CDATA[msmtp]]></category>

		<guid isPermaLink="false">http://therning.org/magnus/?p=656</guid>
		<description><![CDATA[To get darcs to use msmtp I put the following in my ~/.darcs/defaults: send sendmail-command /usr/bin/msmtp %t %&#60;]]></description>
			<content:encoded><![CDATA[<p>To get <a href="http://www.darcs.net/">darcs</a> to use <code>msmtp</code> I put the following in my <code>~/.darcs/defaults</code>:</p>


<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">send sendmail-command /usr/bin/msmtp %t %&lt;</pre></div></div>

<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Bookmark</a> </p>]]></content:encoded>
			<wfw:commentRss>http://therning.org/magnus/archives/656/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Using msmtp with Mercurial</title>
		<link>http://therning.org/magnus/archives/651</link>
		<comments>http://therning.org/magnus/archives/651#comments</comments>
		<pubDate>Tue, 09 Jun 2009 11:05:14 +0000</pubDate>
		<dc:creator>Magnus</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[hg]]></category>
		<category><![CDATA[mercurial]]></category>
		<category><![CDATA[msmtp]]></category>

		<guid isPermaLink="false">http://therning.org/magnus/?p=651</guid>
		<description><![CDATA[After configuring msmtp I put the following in my ~/.hgrc: &#91;extensions&#93; hgext.patchbomb = &#160; &#91;email&#93; from = my.email@my.isp.com method = /usr/bin/msmtp]]></description>
			<content:encoded><![CDATA[<p>After configuring <code>msmtp</code> I put the following in my <code>~/.hgrc</code>:</p>


<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;"><span style="color: #000066; font-weight:bold;"><span style="">&#91;</span>extensions<span style="">&#93;</span></span>
hgext.patchbomb <span style="color: #000066; font-weight:bold;">=</span>
&nbsp;
<span style="color: #000066; font-weight:bold;"><span style="">&#91;</span>email<span style="">&#93;</span></span>
<span style="color: #000099;">from</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> my.email@my.isp.com</span>
<span style="color: #000099;">method</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> /usr/bin/msmtp</span></pre></div></div>

<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Bookmark</a> </p>]]></content:encoded>
			<wfw:commentRss>http://therning.org/magnus/archives/651/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using msmtp for a desktop system</title>
		<link>http://therning.org/magnus/archives/647</link>
		<comments>http://therning.org/magnus/archives/647#comments</comments>
		<pubDate>Fri, 05 Jun 2009 22:44:22 +0000</pubDate>
		<dc:creator>Magnus</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[arch]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[fcron]]></category>
		<category><![CDATA[msmtp]]></category>

		<guid isPermaLink="false">http://therning.org/magnus/?p=647</guid>
		<description><![CDATA[I read all my email via IMAP, and send all email via external SMTP servers, but at times it&#8217;s really useful to be able to run something like /usr/sbin/sendmail to send an email. Many tools depend on it, for me I want reports on cron jobs and I like using darcs send straight to an [...]]]></description>
			<content:encoded><![CDATA[<p>I read all my email via IMAP, and send all email via external SMTP servers, but at times it&#8217;s really useful to be able to run something like <code>/usr/sbin/sendmail</code> to send an email.  Many tools depend on it, for me I want reports on <code>cron</code> jobs and I like using <code>darcs send</code> straight to an email address.  For this a full-fledged SMTP server like exim/postfix/sendmail clearly is overkill.  First I had a quick look at <a href="http://www.archlinux.org/packages/extra/x86_64/ssmtp/">ssmtp</a> but it only allows for a system-wide configuration file.  Ideally I&#8217;d like &#8220;system-mails&#8221; (like <code>cron</code>) to be sent via my ISP while more personal emails should be sent via my Google account.  After a suggestion on the Arch mailing list I checked out <a href="http://www.archlinux.org/packages/extra/x86_64/msmtp/">msmtp</a> and it was exactly what I was looking for.</p>

<p>I created <code>/etc/msmtprc</code> with the following contents:</p>


<div class="wp_syntax"><div class="code"><pre class="foo" style="font-family:monospace;">defaults
logfile ~/.msmtp.log
&nbsp;
# MyISP
account myisp
host smtp.myisp.com
from my.email@myisp.com
&nbsp;
account default : myisp</pre></div></div>


<p>I then found out that [dcron][3] is severely limited; it doesn&#8217;t honour <code>MAILTO</code> in <code>crontabs</code> and it&#8217;s not possibly to use anything but <code>/usr/sbin/sendmail</code> to send emails.  The lack of support for <code>MAILTO</code> is the deal breaker in this case.</p>

<p>Rather than create a symbolic link I modified <code>fcron</code>&#8216;s configuration file, <code>/etc/fcron/fcron.conf</code>, to use <code>/usr/bin/msmtp</code>:</p>


<div class="wp_syntax"><div class="code"><pre class="foo" style="font-family:monospace;">sendmail = /usr/bin/msmtp</pre></div></div>


<p>I also made sure to stick <code>MAILTO=my.email@myisp.com</code> in the system <code>crontab</code>, using <code>fcrontab -u systab -e</code>.</p>

<p>Then I created the file <code>~/.msmtprc</code>:</p>


<div class="wp_syntax"><div class="code"><pre class="foo" style="font-family:monospace;">defaults
logfile ~/.msmtp.log
&nbsp;
# MyISP
account mysisp
host smtp.myisp.com
from my.email@myisp.com
&nbsp;
# google
account google
host smtp.gmail.com
from user@googlemail.com
tls on
tls_certcheck off
auth on
user user@googlemail.com
password MySecretPassword
&nbsp;
account default : google</pre></div></div>


<p>Finally I put <code>MAILTO=user@googlemail.com</code> in my user&#8217;s <code>crontab</code>.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Bookmark</a> </p>]]></content:encoded>
			<wfw:commentRss>http://therning.org/magnus/archives/647/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Reply to Randal on dynamic type systems</title>
		<link>http://therning.org/magnus/archives/629</link>
		<comments>http://therning.org/magnus/archives/629#comments</comments>
		<pubDate>Thu, 14 May 2009 09:27:00 +0000</pubDate>
		<dc:creator>Magnus</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[dynamic languages]]></category>
		<category><![CDATA[floss weekly]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[randal schwartz]]></category>

		<guid isPermaLink="false">http://therning.org/magnus/?p=629</guid>
		<description><![CDATA[At first this I wrote this as a comment on my original post, but it grew a bit too long so I decided to post it like this instead. @Randal, &#8220;Static typing is still effectively a syntax check, not a semantic check though.&#8221; Now, I think we might have a different understanding of the word [...]]]></description>
			<content:encoded><![CDATA[<p>At first this I wrote this as a comment on my <a href="http://therning.org/magnus/archives/620">original post</a>, but it grew a bit too long so I decided to post it like this instead.</p>

<p><strong>@Randal</strong>, &#8220;Static typing is still effectively a syntax check, not a semantic check though.&#8221;  Now, I think we might have a different understanding of the word &#8220;syntax&#8221;.  I can guess at yours, but my understanding mirrors what&#8217;s on <a href="http://foldoc.org/syntax">Foldoc</a>, that is syntax determines what is a valid string in a program, in this case it determines <em>where</em> a type declaration/definition/statement goes, but not <em>what</em> type declaration/definition/statement is <em>semantically</em> valid in a particular position in a string.  That &#8220;<em>what</em>&#8221; is very much part of the semantics in my mind, it tells the world (me, other users of my library, the compiler) a part of the intention of a function, it tells how something may be used.  I gather you are mostly familiar with type systems like Java so what is clearer to you, this declaration:</p>


<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">int</span> add<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i, <span style="color: #000066; font-weight: bold;">int</span> j<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>


<p>or this declaration:</p>


<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">int</span> add<span style="color: #009900;">&#40;</span>i, j<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>


<p>In the former the intent of the function is obvious, it adds integers.  In the latter it isn&#8217;t, does it handle complex numbers?  Does it handle matrices?  In dynamic languages you&#8217;d have to document it somewhere, but there is no consistency check between code and documentation (maybe there are external tools for that though, but why not use the compiler to check?).  You would also have to test that no caller of this function can be tricked into calling <code>add</code> with a non-integer.</p>

<p>Also, though your example of &#8220;semantic type checking&#8221; in the talk is interesting (I simply don&#8217;t know if there are any type systems that could deal with it) you completely skip all the cases where the type system <em>can</em> do the job and where it <em>does</em> save on testing and typing.  In these cases you would have a <em>proof</em> relating to your use of types in the program, unit testing can <em>never</em> give that proof it can only show you haven&#8217;t disproved it yet <img src='http://therning.org/magnus/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>

<p>If you remain unconvinced then I strongly urge you to read <a href="http://blog.moertel.com/articles/2006/10/18/a-type-based-solution-to-the-strings-problem">Tom Moertel&#8217;s post on providing safe strings</a>, and the assurance you can achieve by using a strong type system in relation to information flow through your program.  The same technique has been used in Darcs (watch the <a href="http://www.londonhug.net/2008/02/02/video-darcs-and-gadts/">video</a>, the bit relevant for this dicussion starts about 43 minutes in).</p>

<p>I urge you to read Kristian&#8217;s blog post (linked to in his <a href="http://therning.org/magnus/archives/620#comment-178794">comment</a>).</p>

<p>If you want a podcast to listen to there&#8217;s <a href="http://www.se-radio.net/podcast/2007-07/episode-62-martin-odersky-scala">episode 62 of Software Engineering Radio</a> where Martin Odersky talks about Scala (a statically typed language built on the JVM).</p>

<p>I&#8217;d also like to clear one thing up, I don&#8217;t dislike dynamic languages and I don&#8217;t think that static languages are inherently better.  What I do dislike about your talk is that it&#8217;s uninformed, presents very narrow arguments and then draws conclusions that are very general and simply don&#8217;t follow from the given arguments.</p>

<p>Finally, I <em>really</em> enjoy <a href="http://twit.tv/FLOSS">FLOSS Weekly</a>.  You and Leo are doing a fantastic job on it, but since it is where I first heard of your talk (I suspect <a href="http://www.cincomsmalltalk.com/blog/blogView?searchCategory=podcast">Industry Misinterpretations</a> might not get a lot of attention outside the Smalltalk community) I really think you should talk to someone from the FLOSS FP community.  Get someone who can explain, much better than me, what a modern, advanced, strong, statically typed language will get you.  I only have experience with OCaml and Haskell, and there are others, like Scala, all are FLOSS and hopefully it wouldn&#8217;t be too much work to find someone knowledgable who&#8217;d be willing to set you straight on the dynamic vs static typing issue.  I&#8217;d be happy to do what I can to help you find someone, just let me know if you are insterested <img src='http://therning.org/magnus/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Bookmark</a> </p>]]></content:encoded>
			<wfw:commentRss>http://therning.org/magnus/archives/629/feed</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Struggling with &#8220;the Arch way&#8221;</title>
		<link>http://therning.org/magnus/archives/626</link>
		<comments>http://therning.org/magnus/archives/626#comments</comments>
		<pubDate>Wed, 13 May 2009 20:54:20 +0000</pubDate>
		<dc:creator>Magnus</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[arch]]></category>
		<category><![CDATA[aur]]></category>
		<category><![CDATA[getlatestvimscripts]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[haskellmode]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://therning.org/magnus/?p=626</guid>
		<description><![CDATA[So, I&#8217;m struggling somewhat with the move to Arch. Not that Arch is problematic in any way, it seems to be me and my &#8220;debianised thinking&#8221;. I noticed that the Vim plugins that were packaged for Arch all install in system directories and hence are imposed on all users. Not a good thing. So, inspired [...]]]></description>
			<content:encoded><![CDATA[<p>So, I&#8217;m struggling somewhat with the move to Arch.  Not that Arch is
problematic in any way, it seems to be me and my &#8220;debianised thinking&#8221;.</p>

<p>I noticed that the Vim plugins that were packaged for Arch all install in
system directories and hence are imposed on all users.  Not a good thing.  So,
inspired by Debian&#8217;s <a href="http://packages.debian.org/search?keywords=vim-addon-manager">vim-addons-manager</a>, I hacked up a solution relying
on pacman.  Then I packaged two Vim plugins for Arch.  The idea was to do
rather than talk, so it wasn&#8217;t until after this that I asked for feedback on
<a href="http://www.archlinux.org/pipermail/aur-general/2009-May/004861.html">aur-general</a>.  Just to have the idea shot down <img src='http://therning.org/magnus/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>

<p>Anyway, after being presented with an existing solution more inline with &#8220;the
Arch way&#8221; I decided to try it out.  I&#8217;ve now subscribed to using
<a href="http://www.vim.org/scripts/script.php?script_id=642">GetLatestVimScripts</a>.  Brilliant.</p>

<p>Now I need to convince the author of <code>haskellmode</code> to put it on <a href="http://www.vim.org/">vim.org</a>
and I really ought to get my packages off AUR.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Bookmark</a> </p>]]></content:encoded>
			<wfw:commentRss>http://therning.org/magnus/archives/626/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Randal Schwartz on why dynamic beat static&#8212;a rather rubbish talk</title>
		<link>http://therning.org/magnus/archives/620</link>
		<comments>http://therning.org/magnus/archives/620#comments</comments>
		<pubDate>Wed, 13 May 2009 20:22:53 +0000</pubDate>
		<dc:creator>Magnus</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[don stewart]]></category>
		<category><![CDATA[floss weekly]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[randal schwartz]]></category>

		<guid isPermaLink="false">http://therning.org/magnus/?p=620</guid>
		<description><![CDATA[Well, not the most diplomatic title maybe, but listening to Randal Schwartz&#8217; talk &#8220;Dynamic Returns&#8221; first made me laugh and then made my fingers itch to write him an email addressing the fallacies he is peddling. Anyway, I wrote this large, rather ranting, blog post but then decided to not publish iti. Randal, my suggestion [...]]]></description>
			<content:encoded><![CDATA[<p>Well, not the most diplomatic title maybe, but listening to <a href="http://www.cincomsmalltalk.com/blog/SingleView.ssp?showComments=true&amp;entry=3419405760">Randal Schwartz&#8217; talk &#8220;Dynamic Returns&#8221;</a> first made me laugh and then made my fingers itch to write him an email addressing the fallacies he is peddling.  Anyway, I wrote this large, rather ranting, blog post but then decided to not publish it<sup><a href="http://therning.org/magnus/archives/620#footnote_0_620" id="identifier_0_620" class="footnote-link footnote-identifier-link" title="Randal, if you read this I&amp;#8217;ll be happy to send the draft version of the post to you, just drop me an email   ">i</a></sup>.</p>

<p>Randal, my suggestion to you is that you get someone like Don Stewart on FLOSS Weekly (I believe he is based in Portland as well) to discuss how Haskell&#8217;s advanced type system can be harnessed to completely remove whole classes of bugs.</p>
<ol class="footnotes"><li id="footnote_0_620" class="footnote">Randal, if you read this I&#8217;ll be happy to send the draft version of the post to you, just drop me an email <img src='http://therning.org/magnus/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  </li></ol><p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Bookmark</a> </p>]]></content:encoded>
			<wfw:commentRss>http://therning.org/magnus/archives/620/feed</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Vim haskellmode packaged for Arch</title>
		<link>http://therning.org/magnus/archives/617</link>
		<comments>http://therning.org/magnus/archives/617#comments</comments>
		<pubDate>Mon, 11 May 2009 20:57:29 +0000</pubDate>
		<dc:creator>Magnus</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[arch]]></category>
		<category><![CDATA[aur]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://therning.org/magnus/?p=617</guid>
		<description><![CDATA[A few days ago I packaged the vim haskellmode for Arch Linux and uploaded it to AUR.]]></description>
			<content:encoded><![CDATA[<p>A few days ago I packaged the <a href="http://projects.haskell.org/haskellmode-vim/">vim haskellmode</a> for Arch Linux and uploaded it to <a href="http://aur.archlinux.org/packages.php?ID=26343">AUR</a>.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Bookmark</a> </p>]]></content:encoded>
			<wfw:commentRss>http://therning.org/magnus/archives/617/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Configuring audio for my Arch desktop</title>
		<link>http://therning.org/magnus/archives/611</link>
		<comments>http://therning.org/magnus/archives/611#comments</comments>
		<pubDate>Sat, 09 May 2009 20:07:37 +0000</pubDate>
		<dc:creator>Magnus</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[alsa]]></category>
		<category><![CDATA[arch]]></category>
		<category><![CDATA[pulseaudio]]></category>

		<guid isPermaLink="false">http://therning.org/magnus/?p=611</guid>
		<description><![CDATA[I probably started in the wrong end, by installing a few GStreamer packages: gstreamer0.10-bad-plugins gstreamer0.10-ugly-plugins gstreamer0.10-ffmpeg It was first after that that I actually configured sound As always the Arch Wiki contains all the information needed, and more. There&#8217;s a page for configuring Alsa. All I did was install alsa-utils, make sure my user was [...]]]></description>
			<content:encoded><![CDATA[<p>I probably started in the wrong end, by installing a few GStreamer packages:</p>

<ol>
<li><em>gstreamer0.10-bad-plugins</em></li>
<li><em>gstreamer0.10-ugly-plugins</em></li>
<li><em>gstreamer0.10-ffmpeg</em></li>
</ol>

<p>It was first after that that I actually configured sound <img src='http://therning.org/magnus/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>

<p>As always the <a href="http://wiki.archlinux.org/">Arch Wiki</a> contains all the information needed, and more.
There&#8217;s a page for <a href="http://wiki.archlinux.org/index.php/ALSA">configuring Alsa</a>.  All I did was install <em>alsa-utils</em>, make sure my user was a member of <code>audio</code> and
then configure using <code>alsamixer</code> until <code>aplay
/usr/share/sounds/alsa/Front_Center.wav</code> played properly.  Then I put <code>alsa</code>
in the <code>DEAMON</code> list in <code>/etc/rc.conf</code>.</p>

<p>Next I installed and configured <a href="http://www.pulseaudio.org/">PulseAudio</a>.  Again there&#8217;s an excellent
page with instructions for <a href="http://wiki.archlinux.org/index.php/PulseAudio">configuring PulseAudio</a> on the wiki.  For me
that meant first installing <em>pulseaudio</em> and <em>alsa-plugins</em>.  Then I used
<code>vigr</code> to add my user to <code>pulse-access</code> and <code>pulse-rt</code>.  I also created
<code>/etc/asound.conf</code>, following the instruction on the wiki it contains the
following:</p>

<pre><code>pcm.pulse {
    type pulse
}
ctl.pulse {
    type pulse
}

pcm.!default {
    type pulse
}
ctl.!default {
    type pulse
}
</code></pre>

<p>I then double checked that PulseAudio uses HAL to detect the needed modules.
Lastly I made it possible for gstreamer to use PulseAudio by installing
<em>gstreamer0.10-pulse</em>.</p>

<p><em>[edited 22/5/2009]</em> Added info on group membership.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Bookmark</a> </p>]]></content:encoded>
			<wfw:commentRss>http://therning.org/magnus/archives/611/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Odds and ends for my Arch desktop</title>
		<link>http://therning.org/magnus/archives/603</link>
		<comments>http://therning.org/magnus/archives/603#comments</comments>
		<pubDate>Sat, 09 May 2009 18:02:47 +0000</pubDate>
		<dc:creator>Magnus</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[arch]]></category>
		<category><![CDATA[aur]]></category>
		<category><![CDATA[hpodder]]></category>
		<category><![CDATA[keysafe]]></category>
		<category><![CDATA[yaourt]]></category>

		<guid isPermaLink="false">http://therning.org/magnus/?p=603</guid>
		<description><![CDATA[After the previous setup steps I found the next task was to add a few odds and ends really were needed before proceeding to other major things, like audio, email, and such. Several of the things I needed are available from AUR so to make things easier I started by adding archlinuxfr to my /etc/pacman.conf: [...]]]></description>
			<content:encoded><![CDATA[<p>After the <a href="http://therning.org/magnus/archives/577">previous</a> <a href="http://therning.org/magnus/archives/586">setup</a> <a href="http://therning.org/magnus/archives/595">steps</a> I found the next task was to add
a few odds and ends really were needed before proceeding to other major
things, like audio, email, and such.  Several of the things I needed are
available from <a href="http://aur.archlinux.org/">AUR</a> so to make things easier I started by adding
<code>archlinuxfr</code> to my <code>/etc/pacman.conf</code>:</p>

<pre><code>--- pacman.conf_orig    2009-05-09 18:47:19.825013872 +0100
+++ pacman.conf 2009-04-26 08:22:05.471685249 +0100
@@ -70,6 +70,9 @@
 # Add your preferred servers here, they will be used first
 Include = /etc/pacman.d/mirrorlist

+[archlinuxfr]
+Server = http://repo.archlinux.fr/x86_64
+
 # An example of a custom package repository.  See the pacman manpage for
 # tips on creating your own repositories.
 #[custom]
</code></pre>

<p>After that I updated the package listings (<code>pacman -Sy</code>) and installed <em>yaourt</em>
(<code>pacman -S yaourt</code>).</p>

<p>After this I could easily install the other packages I need:</p>

<ol>
<li><em>nautilus-dropbox</em></li>
<li><em>encfs</em></li>
<li><em>pam_mount</em></li>
<li><em>keysafe</em></li>
<li><em>hpodder</em></li>
<li><em>twitux</em></li>
</ol>

<p>Only <em>pam_mount</em> needed some extra configuration.  First I added two lines each to <code>/etc/pam.d/gdm</code> and <code>/etc/pam.d/login</code>:</p>

<pre><code>auth        optional    pam_mount.so
session     optional    pam_mount.so
</code></pre>

<p>Then I modified <code>/etc/security/pam_mount.conf.xml</code> to allow users to have their own configs, that&#8217;s done by uncommenting the line</p>

<pre><code>&lt;luserconf name=".pam_mount.conf.xml" /&gt;
</code></pre>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Bookmark</a> </p>]]></content:encoded>
			<wfw:commentRss>http://therning.org/magnus/archives/603/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Arch and Haskell, on little snag</title>
		<link>http://therning.org/magnus/archives/599</link>
		<comments>http://therning.org/magnus/archives/599#comments</comments>
		<pubDate>Sat, 09 May 2009 10:44:26 +0000</pubDate>
		<dc:creator>Magnus</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[arch]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[LazyWeb]]></category>
		<category><![CDATA[yaourt]]></category>

		<guid isPermaLink="false">http://therning.org/magnus/?p=599</guid>
		<description><![CDATA[Dear lazyweb (Arch users and especially DonS ), I just used yaourt to update my system and it noticed that haskell-time was available in a new version. After answering a few questions I was greeted with this message: ghc-pkg: unregistering time-1.1.2.3 would break the following packages: hslogger-1.0.7 MissingH-1.1.0 ConfigFile-1.0.4 convertible-1.0.1 HDBC-2.1.0 HDBC-sqlite3-2.1.0.0 HSH-1.2.6 (use --force [...]]]></description>
			<content:encoded><![CDATA[<p>Dear lazyweb (Arch users and especially DonS <img src='http://therning.org/magnus/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  ),</p>

<p>I just used <code>yaourt</code> to update my system and it noticed that <code>haskell-time</code> was available in a new version.  After answering a few questions I was greeted with this message:</p>

<pre><code>ghc-pkg: unregistering time-1.1.2.3 would break the following packages: hslogger-1.0.7 MissingH-1.1.0
    ConfigFile-1.0.4 convertible-1.0.1 HDBC-2.1.0 HDBC-sqlite3-2.1.0.0 HSH-1.2.6 (use --force to override)
error: scriptlet failed to execute correctly
</code></pre>

<p>Is there already some automated way to deal with this?  (How to deal with it manually is fairly obvious to me&#8230;)</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Bookmark</a> </p>]]></content:encoded>
			<wfw:commentRss>http://therning.org/magnus/archives/599/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Setting up my network services on Arch</title>
		<link>http://therning.org/magnus/archives/595</link>
		<comments>http://therning.org/magnus/archives/595#comments</comments>
		<pubDate>Sat, 02 May 2009 20:52:16 +0000</pubDate>
		<dc:creator>Magnus</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[arch]]></category>
		<category><![CDATA[avahi]]></category>
		<category><![CDATA[mdns]]></category>
		<category><![CDATA[openntp]]></category>
		<category><![CDATA[openssh]]></category>
		<category><![CDATA[ssh]]></category>

		<guid isPermaLink="false">http://therning.org/magnus/?p=595</guid>
		<description><![CDATA[After having set up X (not sure I really can call just installing it &#8220;setting up&#8221; though ) and Gnome, which of course included installing and configuring Xmonad, I went on to configure some network-related stuff. At home I use mDNS to make it easy to connect to the computers we have at home. I [...]]]></description>
			<content:encoded><![CDATA[<p>After having set up X (not sure I really can call just installing it &#8220;setting
up&#8221; though <img src='http://therning.org/magnus/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  ) and Gnome, which of course included installing and
configuring Xmonad, I went on to configure some network-related stuff.</p>

<p>At home I use mDNS to make it easy to connect to the computers we have at
home.  I added <code>avahi</code> to the list of services to start in <code>/etc/rc.conf</code> and
installed <code>nss-mdns</code>.  Then I following the instructions on how to <a href="http://wiki.archlinux.org/index.php/Avahi#Hostname_resolution">configure
mDNS on Arch</a>, which resulted in the following changes:</p>

<pre><code>--- /etc/nsswitch.conf_old  2009-05-02 21:17:06.460591935 +0100
+++ /etc/nsswitch.conf  2009-04-25 18:08:39.719853968 +0100
@@ -6,7 +6,7 @@

 publickey: files

-hosts: files dns
+hosts: files mdns_minimal [NOTFOUND=return] dns mdns
 networks: files

 protocols: db files
</code></pre>

<p>I also need SSH access to my desktop machine so I installed OpenSSH
(<code>openssh</code>).  No changes were needed to the configuration but following <a href="http://wiki.archlinux.org/index.php/SSH#Allowing_others_in">the
instructions</a> I made the following change to <code>/etc/hosts.allow</code> to allow
connections at all:</p>

<pre><code>--- /etc/hosts.allow_orig   2009-05-02 21:31:16.243401337 +0100
+++ /etc/hosts.allow    2009-04-28 17:55:57.553603986 +0100
@@ -2,5 +2,6 @@
 # /etc/hosts.allow
 #

+sshd: ALL

 # End of file
</code></pre>

<p>Then of course I added <code>sshd</code> to the list of services in <code>/etc/rc.conf</code>.</p>

<p>The last step was setting up NTP, based on suggestions on the Arch Wiki I
installed OpenNTP (<code>openntp</code>) rather than the standard NTP package.  No
changes to the configuration were needed, just adding it to <code>DAEMONS</code> in
<code>/etc/rc.conf</code>.</p>

<p>That was it, all the crucial network-related services set up and running at
boot.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Bookmark</a> </p>]]></content:encoded>
			<wfw:commentRss>http://therning.org/magnus/archives/595/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Arch, Gnome, and shutdown/reboot</title>
		<link>http://therning.org/magnus/archives/590</link>
		<comments>http://therning.org/magnus/archives/590#comments</comments>
		<pubDate>Sat, 02 May 2009 16:18:44 +0000</pubDate>
		<dc:creator>Magnus</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[arch]]></category>
		<category><![CDATA[gnome]]></category>

		<guid isPermaLink="false">http://therning.org/magnus/?p=590</guid>
		<description><![CDATA[I&#8217;ll soon continue documenting my experience with installing and configuring my desktop, but first a note on fixing an irritating issue in Gnome 2.26. Soon after installing Gnome I noticed that I couldn&#8217;t reboot or shutdown from inside my Gnome session, I had to log out and use GDM&#8217;s action menu instead. Rather irritating, but [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ll soon continue documenting my experience with installing and configuring my desktop, but first a note on fixing an irritating issue in Gnome 2.26.  Soon after installing Gnome I noticed that I couldn&#8217;t reboot or shutdown from inside my Gnome session, I had to log out and use GDM&#8217;s action menu instead.  Rather irritating, but something I could live with until the weekend.  It took a while to find the solution so to safe myself time in the future I&#8217;ll document it here.  It might even help someone else, who knows?</p>

<p>Whenever I tried to reboot or shutdown I saw the following message appear in <code>~/.xsession-errors</code>:</p>

<pre><code>gnome-session[4134]: WARNING: Unable to list sessions: Rejected send message, 2 matched rules;
type="method_call", sender=":1.50" (uid=1000 pid=4134 comm="gnome-session ")
interface="org.freedesktop.ConsoleKit.Manager" member="GetSessions" error name="(unset)"
requested_reply=0 destination="org.freedesktop.ConsoleKit" (uid=0 pid=2838
comm="/usr/sbin/console-kit-daemon "))
</code></pre>

<p>After giving up on finding a solution with Google I turned to <code>#archlinux</code> and was pointed to a <a href="http://bbs.archlinux.org/viewtopic.php?id=70803">forum post</a>.  That discussion doesn&#8217;t mention the warning message at all, so it wasn&#8217;t obvious to me at first that it was the same issue.  However, about half-way down the page I found <a href="http://bbs.archlinux.org/viewtopic.php?pid=543614#p543614">a post by justusjonas</a> that looked relevant.  I tried that change, or rather something very similar, and a manual reboot later I could confirm that the change indeed fixed the issue.  This is the change I applied:</p>

<pre><code>--- /etc/dbus-1/system.d/ConsoleKit.conf_org    2009-05-02 15:59:40.235077390 +0100
+++ /etc/dbus-1/system.d/ConsoleKit.conf    2009-05-02 16:00:10.108231150 +0100
@@ -32,6 +32,8 @@
     &lt;allow send_interface="org.freedesktop.ConsoleKit.Manager"
            send_member="GetSeats"/&gt;
     &lt;allow send_interface="org.freedesktop.ConsoleKit.Manager"
+           send_member="GetSessions"/&gt;
+    &lt;allow send_interface="org.freedesktop.ConsoleKit.Manager"
            send_member="GetSessionForCookie"/&gt;
     &lt;allow send_interface="org.freedesktop.ConsoleKit.Manager"
            send_member="GetSessionForUnixProcess"/&gt;
</code></pre>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Bookmark</a> </p>]]></content:encoded>
			<wfw:commentRss>http://therning.org/magnus/archives/590/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>More on the move to Arch Linux</title>
		<link>http://therning.org/magnus/archives/586</link>
		<comments>http://therning.org/magnus/archives/586#comments</comments>
		<pubDate>Thu, 30 Apr 2009 22:49:37 +0000</pubDate>
		<dc:creator>Magnus</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[arch]]></category>
		<category><![CDATA[gnome]]></category>
		<category><![CDATA[gpg]]></category>
		<category><![CDATA[xmonad]]></category>

		<guid isPermaLink="false">http://therning.org/magnus/?p=586</guid>
		<description><![CDATA[After installing a basic Arch system and adding X.org it still isn&#8217;t very usable. My desktop of choice is Gnome, so that&#8217;s what I installed next, with a few extra packages to make it prettier and more useful. I found out the hard way a few weeks ago that if you install gnome without gnome-extras [...]]]></description>
			<content:encoded><![CDATA[<p>After installing a basic Arch system and adding X.org it still isn&#8217;t very
usable.  My desktop of choice is Gnome, so that&#8217;s what I installed next, with
a few extra packages to make it prettier and more useful.</p>

<p>I found out the hard way a few weeks ago that if you install <code>gnome</code> without
<code>gnome-extras</code> then it&#8217;s a bad idea to install <code>gdm</code> and configure your system
to boot to X.  That way you&#8217;ll end up in a situation where your desktop
doesn&#8217;t have an X terminal.  I made sure to avoid that situation this time
around.  After installing <code>gnome</code>,<code>gnome-extras</code> and <code>gdm</code> I noticed that both
<code>gdm</code> and <code>policykit</code> created users with uid 120 and 102, respectively.  Just
like exptected from services they have low uids.  What surprised me was that
they ended up having gid 1001 and 1002.  That looks like <a href="http://bugs.archlinux.org/task/13690">bugs</a> <a href="http://bugs.archlinux.org/task/14507">to me</a> <img src='http://therning.org/magnus/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />   I decided to fix that up manually myself by editing the group file (using
<code>vigr</code> of course) and then searching for all file with the offending gids
(using <code>find / -gid 1001</code> for the first, with obvious changes to find the
second).</p>

<p>After configuring <code>gdm</code> I realised I also needed <code>gdm-themes</code> <img src='http://therning.org/magnus/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />   And I also
added a few pretty fonts, and removed a few of the unpretty ones:</p>

<pre><code># pacman -S ttf-ms-fonts ttf-cheapskate artwiz-fonts ttf-bitstream-vera
# pacman -Rns xorg-fonts-75dpi xorg-fonts-100dpi
</code></pre>

<p>Then of course I needed to install <a href="http://www.xmonad.org/">xmonad</a>:</p>

<pre><code># pacman -S xmonad-contrib
</code></pre>

<p>Co-ercing Gnome to actually use it was interesting though.  I followed the
instructions for running <a href="http://haskell.org/haskellwiki/Xmonad/Using_xmonad_in_Gnome#Ubuntu_Jaunty">Xmonad in Jaunty</a>, but that wasn&#8217;t enough.  I
also needed to place a file named <code>xmonad.desktop</code> in
<code>/usr/share/applications/</code> with the following contents (greatly inspired by
the <code>metacity.desktop</code> found in the same location):</p>

<pre><code>[Desktop Entry]
Type=Application
Encoding=UTF-8
Name=Xmonad
Exec=xmonad
NoDisplay=true
X-GNOME-WMName=Xmonad
X-GNOME-Autostart-Phase=WindowManager
X-GNOME-Provides=windowmanager
</code></pre>

<p>After that it was time to install stuff that is useful <img src='http://therning.org/magnus/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />   First off was
<a href="http://www.mozillamessaging.com/en-US/thunderbird/">Thunderbird</a>, which I immidiately had to equip with a few plug-ins of
course.  When setting up my mail account again I noticed that my Gnome session
wasn&#8217;t quite the way I wanted&#8212;there was no gpg-agent running.  After a quick
check with the people on <a href="http://www.archlinux.org/pipermail/arch-general/2009-April/004804.html">arch-general</a>, without receiving any definitive
resolution, I wrote my own little hack to address it.  Of course I posted it
in the thread I had started, but I might as well include it here too:</p>

<pre><code>--- /etc/gdm/Xsession_orig  2009-04-27 17:13:50.346834448 +0100
+++ /etc/gdm/Xsession   2009-04-27 17:16:25.310151728 +0100
@@ -213,6 +213,14 @@
   fi
 fi

+# add seahorse if found
+seahorse="`gdmwhich seahorse-agent`"
+if [ -n "${seahorse}" ] &amp;&amp; [ -x "${seahorse}" ]; then
+    command="seahorse-agent --execute $command"
+elif [ -z "${seahorse}" ]; then
+    echo "$0: seahorse not found!"
+fi
+
 # add ssh-agent if found
 sshagent="`gdmwhich ssh-agent`"
 if [ -n "$sshagent" ] &amp;&amp; [ -x "$sshagent" ] &amp;&amp; [ -z "$SSH_AUTH_SOCK" ]; then
</code></pre>

<p>There&#8217;s one more tool I can&#8217;t live without, <code>parcellite</code>, which is also
available pre-built on Arch.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Bookmark</a> </p>]]></content:encoded>
			<wfw:commentRss>http://therning.org/magnus/archives/586/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Moving to Arch Linux</title>
		<link>http://therning.org/magnus/archives/577</link>
		<comments>http://therning.org/magnus/archives/577#comments</comments>
		<pubDate>Tue, 28 Apr 2009 21:56:48 +0000</pubDate>
		<dc:creator>Magnus</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[arch]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://therning.org/magnus/?p=577</guid>
		<description><![CDATA[&#60;rant>So my irritation with Debian on the desktop reached a critical moment over the last few days. Sid is a good desktop system for most things, but if you are interested in Haskell then you really should prepare yourself for being a little behind on things. If it isn&#8217;t GHC that is out of date [...]]]></description>
			<content:encoded><![CDATA[<p>&lt;rant>So my irritation with Debian on the desktop reached a critical moment
over the last few days.  Sid is a good desktop system for most things, but if
you are interested in Haskell then you really should prepare yourself for
being a little behind on things.  If it isn&#8217;t GHC that is out of date then
it&#8217;s some library that hasn&#8217;t been rebuilt for the latest version of GHC.  If
you&#8217;re lucky then new packages are uploaded to the NEW queue and it&#8217;s only a
matter of waiting for the autobuilders to get to them.  Of course that doesn&#8217;t mean you can get those packages, so not that much luck in the end anyway.&lt;/rant></p>

<p>I decided to move to the only other distro I&#8217;ve used seriously since Linux&#8217;
move to 2.x kernels, <a href="http://www.archlinux.org/">Arch</a>.  I remember it as a slightly less polished
than Debian, but more up-to-date than even Sid.  Also, there is a vibrant
group of Haskell hackers working on providing almost all of Hackage in Arch&#8217;s
native packaging system.</p>

<p>Installing Arch turned out to be a bit of a blast from the past, even when
compared to Debian.  Luckily the <a href="http://wiki.archlinux.org/">Arch wiki</a> is there to help with the
things that are different compared to Debian.  I would suggest having a second
computer with a browser pointed to Arch&#8217;s home pages nearby during the entire
install.</p>

<p>For my installation of Debian I had opted to use LVM and I wanted to keep my
<code>/home</code> around so I had to follow the steps required to <a href="http://wiki.archlinux.org/index.php/LVM2">use LVM in Arch</a>.
Installation went smooth and the reboot was successful.  Now starts the hard
work&#8212;configuring the system and updating my home folder.</p>

<p>The very first thing I noticed was that <code>vim</code> wasn&#8217;t installed by default,
only <code>vi</code> was available.  Not a big problem, except that my muscle memory
resulted in a lot of <code>vim: command not found</code> messages.  Clearly I had to install <code>vim</code> just
to keep my sanity.</p>

<p>Next thing to do was to install X.org and the video driver I need:</p>

<pre><code># pacman -S xorg xf86-video-intel
</code></pre>

<p>After adding <code>hal</code> to <code>/etc/rc.conf</code> I started it manually and I ran <code>startx</code>
as non-root.  Wow, it all worked perfect, without creating any configuration
file for X first.  I double checked and it used the driver I wanted, i.e. it
didn&#8217;t pick a safe default, like vesa, as its first option.  Brilliant.</p>

<p>After following the <a href="http://wiki.archlinux.org/index.php/Xorg#Setting_non-us_keyboard_without_xorg.conf">instructions for changing the keyboard layout in X.org
using hal</a> I even had my &#8216;@&#8217; on the right key.  (The most confusing thing
was that in X.org the UK keyboard layout is called <code>gb</code>, while in the console
setup it&#8217;s called <code>uk</code>.)</p>

<p>I&#8217;ll post a bit more about the setup and configuration of my system as I
progress towards my ideal desktop.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Bookmark</a> </p>]]></content:encoded>
			<wfw:commentRss>http://therning.org/magnus/archives/577/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>dataenc 0.12.1.0 released</title>
		<link>http://therning.org/magnus/archives/568</link>
		<comments>http://therning.org/magnus/archives/568#comments</comments>
		<pubDate>Thu, 23 Apr 2009 17:32:20 +0000</pubDate>
		<dc:creator>Magnus</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[dataenc]]></category>
		<category><![CDATA[hackage]]></category>
		<category><![CDATA[haskell]]></category>

		<guid isPermaLink="false">http://therning.org/magnus/?p=568</guid>
		<description><![CDATA[Yesterday I released a new version of dataenc. It&#8217;s available on Hackage of course. Summary of (visible) changes: implementation of a bunch of new encodings: xxencode quoted-printable python escaping url encoding squashing of a bug in the yEncoding implementation that only manifested on 32-bit systems an attempt to conform to the guidelines for the Haskell [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday I released a new version of dataenc.  It&#8217;s <a href="http://hackage.haskell.org/cgi-bin/hackage-scripts/package/dataenc">available on Hackage</a> of course.  Summary of (visible) changes:</p>

<ul>
<li>implementation of a bunch of new encodings:

<ul>
<li>xxencode</li>
<li>quoted-printable</li>
<li>python escaping</li>
<li>url encoding</li>
</ul></li>
<li>squashing of a bug in the yEncoding implementation that only manifested on 32-bit systems</li>
<li>an attempt to conform to the guidelines for the Haskell Platform regarding versioning and dependencies</li>
</ul>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Bookmark</a> </p>]]></content:encoded>
			<wfw:commentRss>http://therning.org/magnus/archives/568/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Missing data encodings?</title>
		<link>http://therning.org/magnus/archives/566</link>
		<comments>http://therning.org/magnus/archives/566#comments</comments>
		<pubDate>Mon, 06 Apr 2009 21:16:26 +0000</pubDate>
		<dc:creator>Magnus</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[data_encoding]]></category>

		<guid isPermaLink="false">http://therning.org/magnus/?p=566</guid>
		<description><![CDATA[Dear lazyweb, are there any useful data encodings missing from the following list? Uuencode Base64 Base64Url Base32 Base32Hex Base16 Base85 yEncoding]]></description>
			<content:encoded><![CDATA[<p>Dear lazyweb, are there any useful data encodings missing from the following list?</p>

<ul>
<li>Uuencode</li>
<li>Base64</li>
<li>Base64Url</li>
<li>Base32</li>
<li>Base32Hex</li>
<li>Base16</li>
<li>Base85</li>
<li>yEncoding</li>
</ul>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">Share/Bookmark</a> </p>]]></content:encoded>
			<wfw:commentRss>http://therning.org/magnus/archives/566/feed</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>
