<?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>It Seemed Like a Good Idea at the Time &#187; coding</title>
	<atom:link href="http://blog.willdonnelly.net/category/coding/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.willdonnelly.net</link>
	<description>Coding, Mostly</description>
	<lastBuildDate>Fri, 20 Aug 2010 15:33:00 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>shsel &#8211; runtime selection of unix shells</title>
		<link>http://blog.willdonnelly.net/2009/12/15/shsel-runtime-selection-of-unix-shells/</link>
		<comments>http://blog.willdonnelly.net/2009/12/15/shsel-runtime-selection-of-unix-shells/#comments</comments>
		<pubDate>Tue, 15 Dec 2009 23:33:18 +0000</pubDate>
		<dc:creator>Will Donnelly</dc:creator>
				<category><![CDATA[c]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[ssh]]></category>

		<guid isPermaLink="false">http://blog.willdonnelly.net/?p=331</guid>
		<description><![CDATA[In an ordinary SSH login, the shell selection mechanism [...]]]></description>
			<content:encoded><![CDATA[<p>In an ordinary SSH login, the shell selection mechanism is <em>boring</em>. You automatically get a single shell, and the only way I know to change said shell requires writing to <code class="codecolorer text default"><span class="text">/etc/passwd</span></code>. Using <code class="codecolorer text default"><span class="text">chsh</span></code> isn't even a <em>possibility</em> unless you're already in an interactive shell, and sometimes I want to create accounts on my machines that simply don't have that level of access.</p>
<p>So I wrote <a href="http://github.com/willdonnelly/shsel/">shsel</a>, a handy little tool which allows me to specify multiple shells a user can choose from at login time. It's simple, weighing in at 100 lines exactly, and allows only the execution of very specific commands read from a configuration file. It's nothing fancy, but I was unable to find any combination of existing tools that would achieve the desired result, so it's nice to have a new program to add to my bag of tricks.</p>
<div class="lightsocial_container"><a class="lightsocial_a" href="http://digg.com/submit?url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F12%2F15%2Fshsel-runtime-selection-of-unix-shells%2F&amp;title=shsel+-+runtime+selection+of+unix+shells" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/digg.png" alt="Digg This" title="Digg This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.reddit.com/submit?url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F12%2F15%2Fshsel-runtime-selection-of-unix-shells%2F&amp;title=shsel+-+runtime+selection+of+unix+shells" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/reddit.png" alt="Reddit This" title="Reddit This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F12%2F15%2Fshsel-runtime-selection-of-unix-shells%2F&amp;title=shsel+-+runtime+selection+of+unix+shells" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/stumbleupon.png" alt="Stumble Now!" title="Stumble Now!" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://buzz.yahoo.com/buzz?targetUrl=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F12%2F15%2Fshsel-runtime-selection-of-unix-shells%2F&amp;headline=shsel+-+runtime+selection+of+unix+shells" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/yahoo_buzz.png" alt="Buzz This" title="Buzz This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dzone.com/links/add.html?title=shsel+-+runtime+selection+of+unix+shells&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F12%2F15%2Fshsel-runtime-selection-of-unix-shells%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/dzone.png" alt="Vote on DZone" title="Vote on DZone" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.facebook.com/sharer.php?t=shsel+-+runtime+selection+of+unix+shells&amp;u=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F12%2F15%2Fshsel-runtime-selection-of-unix-shells%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/facebook.png" alt="Share on Facebook" title="Share on Facebook" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://delicious.com/save?title=shsel+-+runtime+selection+of+unix+shells&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F12%2F15%2Fshsel-runtime-selection-of-unix-shells%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/delicious.png" alt="Bookmark this on Delicious" title="Bookmark this on Delicious" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dotnetkicks.com/kick/?title=shsel+-+runtime+selection+of+unix+shells&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F12%2F15%2Fshsel-runtime-selection-of-unix-shells%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/dotnetkicks.png" alt="Kick It on DotNetKicks.com" title="Kick It on DotNetKicks.com" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://dotnetshoutout.com/Submit?title=shsel+-+runtime+selection+of+unix+shells&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F12%2F15%2Fshsel-runtime-selection-of-unix-shells%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/dotnetshoutout.png" alt="Shout it" title="Shout it" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F12%2F15%2Fshsel-runtime-selection-of-unix-shells%2F&amp;title=shsel+-+runtime+selection+of+unix+shells&amp;summary=&amp;source=" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/linkedin.png" alt="Share on LinkedIn" title="Share on LinkedIn" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.technorati.com/faves?add=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F12%2F15%2Fshsel-runtime-selection-of-unix-shells%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/technorati.png" alt="Bookmark this on Technorati" title="Bookmark this on Technorati" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://twitter.com/home?status=Reading+http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F12%2F15%2Fshsel-runtime-selection-of-unix-shells%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/twitter.png" alt="Post on Twitter" title="Post on Twitter" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.google.com/buzz/post?url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F12%2F15%2Fshsel-runtime-selection-of-unix-shells%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/google_buzz.png" alt="Google Buzz (aka. Google Reader)" title="Google Buzz (aka. Google Reader)" /></a>&nbsp;&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://blog.willdonnelly.net/2009/12/15/shsel-runtime-selection-of-unix-shells/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Solving Logic Grid Puzzles in Haskell</title>
		<link>http://blog.willdonnelly.net/2009/11/06/solving-logic-grid-puzzles-in-haskell/</link>
		<comments>http://blog.willdonnelly.net/2009/11/06/solving-logic-grid-puzzles-in-haskell/#comments</comments>
		<pubDate>Fri, 06 Nov 2009 19:48:05 +0000</pubDate>
		<dc:creator>Will Donnelly</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[haskell]]></category>

		<guid isPermaLink="false">http://willdonnelly.wordpress.com/?p=314</guid>
		<description><![CDATA[The Zebra Puzzle is a decades-old exercise in deductive [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://en.wikipedia.org/wiki/Zebra_Puzzle">Zebra Puzzle</a> is a decades-old exercise in deductive logic. Unfortunately, I lack the patience to sit down and solve this kind of puzzle. So in this post, we're going to cheat by teaching Haskell to solve it for us.</p>
<div class="codecolorer-container haskell default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="haskell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933; font-weight: bold;">&gt;</span> <span style="color: #06c; font-weight: bold;">import</span> Data<span style="color: #339933; font-weight: bold;">.</span><a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#t:Maybe"><span style="color: #cccc00; font-weight: bold;">Maybe</span></a><br />
<span style="color: #339933; font-weight: bold;">&gt;</span> <span style="color: #06c; font-weight: bold;">import</span> Control<span style="color: #339933; font-weight: bold;">.</span><a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#t:Monad"><span style="color: #cccc00; font-weight: bold;">Monad</span></a></div></div>
<p>We will take our cue from <a href="http://sandbox.rulemaker.net/ngps/119">this solution</a> written in SWI Prolog, and encode our puzzle as a set of constraints that our solving code must satisfy.</p>
<p>An 'entry' is a single entity in the solution. In the Zebra puzzle, these are going to be the individual houses. For maximum generality, we're just going to represent all the properties of the entries with strings.</p>
<p>An answer to the puzzle is a collection of several entities which together satisfy all of the rules set forth in the puzzle description.</p>
<div class="codecolorer-container haskell default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="haskell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933; font-weight: bold;">&gt;</span> <span style="color: #06c; font-weight: bold;">type</span> Entry &nbsp;<span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#91;</span><a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#t:String"><span style="color: #cccc00; font-weight: bold;">String</span></a><span style="color: green;">&#93;</span><br />
<span style="color: #339933; font-weight: bold;">&gt;</span> <span style="color: #06c; font-weight: bold;">type</span> Answer <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#91;</span>Entry<span style="color: green;">&#93;</span></div></div>
<p>I was going to explain the rule types at this point, but the explanation ended up being a lot harder to understand than just looking at the rules for this puzzle, so we'll do that instead.</p>
<p>The first four rules simply teach our solver about numbers. After these rules are satisfied, the entries in the solution will be numbered one through five.</p>
<div class="codecolorer-container haskell default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="haskell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933; font-weight: bold;">&gt;</span> rules <span style="color: #339933; font-weight: bold;">=</span><br />
<span style="color: #339933; font-weight: bold;">&gt;</span> &nbsp; <span style="color: green;">&#91;</span> Follows &nbsp;<span style="color: green;">&#91;</span> <span style="background-color: #3cb371;">&quot;1&quot;</span><span style="color: #339933; font-weight: bold;">,</span> <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; &nbsp;<span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; <span style="background-color: #3cb371;">&quot;&quot;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: green;">&#93;</span><br />
<span style="color: #339933; font-weight: bold;">&gt;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: green;">&#91;</span> <span style="background-color: #3cb371;">&quot;2&quot;</span><span style="color: #339933; font-weight: bold;">,</span> <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; &nbsp;<span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; <span style="background-color: #3cb371;">&quot;&quot;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: green;">&#93;</span><br />
<span style="color: #339933; font-weight: bold;">&gt;</span> &nbsp; <span style="color: #339933; font-weight: bold;">,</span> Follows &nbsp;<span style="color: green;">&#91;</span> <span style="background-color: #3cb371;">&quot;2&quot;</span><span style="color: #339933; font-weight: bold;">,</span> <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; &nbsp;<span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; <span style="background-color: #3cb371;">&quot;&quot;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: green;">&#93;</span><br />
<span style="color: #339933; font-weight: bold;">&gt;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: green;">&#91;</span> <span style="background-color: #3cb371;">&quot;3&quot;</span><span style="color: #339933; font-weight: bold;">,</span> <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; &nbsp;<span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; <span style="background-color: #3cb371;">&quot;&quot;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: green;">&#93;</span><br />
<span style="color: #339933; font-weight: bold;">&gt;</span> &nbsp; <span style="color: #339933; font-weight: bold;">,</span> Follows &nbsp;<span style="color: green;">&#91;</span> <span style="background-color: #3cb371;">&quot;3&quot;</span><span style="color: #339933; font-weight: bold;">,</span> <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; &nbsp;<span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; <span style="background-color: #3cb371;">&quot;&quot;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: green;">&#93;</span><br />
<span style="color: #339933; font-weight: bold;">&gt;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: green;">&#91;</span> <span style="background-color: #3cb371;">&quot;4&quot;</span><span style="color: #339933; font-weight: bold;">,</span> <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; &nbsp;<span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; <span style="background-color: #3cb371;">&quot;&quot;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: green;">&#93;</span><br />
<span style="color: #339933; font-weight: bold;">&gt;</span> &nbsp; <span style="color: #339933; font-weight: bold;">,</span> Follows &nbsp;<span style="color: green;">&#91;</span> <span style="background-color: #3cb371;">&quot;4&quot;</span><span style="color: #339933; font-weight: bold;">,</span> <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; &nbsp;<span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; <span style="background-color: #3cb371;">&quot;&quot;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: green;">&#93;</span><br />
<span style="color: #339933; font-weight: bold;">&gt;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: green;">&#91;</span> <span style="background-color: #3cb371;">&quot;5&quot;</span><span style="color: #339933; font-weight: bold;">,</span> <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; &nbsp;<span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; <span style="background-color: #3cb371;">&quot;&quot;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: green;">&#93;</span></div></div>
<p>Then we specify all of the clues that make up the puzzle itself. These are given in order, so it should be easy to see the correspondence with the clues listed in the wikipedia article</p>
<div class="codecolorer-container haskell default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="haskell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933; font-weight: bold;">&gt;</span> &nbsp; <span style="color: #339933; font-weight: bold;">,</span> Literal &nbsp;<span style="color: green;">&#91;</span> <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp;<span style="background-color: #3cb371;">&quot;England&quot;</span><span style="color: #339933; font-weight: bold;">,</span> <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; <span style="background-color: #3cb371;">&quot;Red&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp;<span style="background-color: #3cb371;">&quot;&quot;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: green;">&#93;</span><br />
<span style="color: #339933; font-weight: bold;">&gt;</span> &nbsp; <span style="color: #339933; font-weight: bold;">,</span> Literal &nbsp;<span style="color: green;">&#91;</span> <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp;<span style="background-color: #3cb371;">&quot;Spain&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; <span style="background-color: #3cb371;">&quot;Dog&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp;<span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; <span style="background-color: #3cb371;">&quot;&quot;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: green;">&#93;</span><br />
<span style="color: #339933; font-weight: bold;">&gt;</span> &nbsp; <span style="color: #339933; font-weight: bold;">,</span> Literal &nbsp;<span style="color: green;">&#91;</span> <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp;<span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; &nbsp;<span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; <span style="background-color: #3cb371;">&quot;Coffee&quot;</span><span style="color: #339933; font-weight: bold;">,</span> <span style="background-color: #3cb371;">&quot;Green&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp;<span style="background-color: #3cb371;">&quot;&quot;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: green;">&#93;</span><br />
<span style="color: #339933; font-weight: bold;">&gt;</span> &nbsp; <span style="color: #339933; font-weight: bold;">,</span> Literal &nbsp;<span style="color: green;">&#91;</span> <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp;<span style="background-color: #3cb371;">&quot;Ukraine&quot;</span><span style="color: #339933; font-weight: bold;">,</span> <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; <span style="background-color: #3cb371;">&quot;Tea&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp;<span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; <span style="background-color: #3cb371;">&quot;&quot;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: green;">&#93;</span><br />
<span style="color: #339933; font-weight: bold;">&gt;</span> &nbsp; <span style="color: #339933; font-weight: bold;">,</span> Follows &nbsp;<span style="color: green;">&#91;</span> <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp;<span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; &nbsp;<span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; <span style="background-color: #3cb371;">&quot;Green&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp;<span style="background-color: #3cb371;">&quot;&quot;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: green;">&#93;</span><br />
<span style="color: #339933; font-weight: bold;">&gt;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: green;">&#91;</span> <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp;<span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; &nbsp;<span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; <span style="background-color: #3cb371;">&quot;Ivory&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp;<span style="background-color: #3cb371;">&quot;&quot;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: green;">&#93;</span><br />
<span style="color: #339933; font-weight: bold;">&gt;</span> &nbsp; <span style="color: #339933; font-weight: bold;">,</span> Literal &nbsp;<span style="color: green;">&#91;</span> <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp;<span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; &nbsp;<span style="background-color: #3cb371;">&quot;Snails&quot;</span><span style="color: #339933; font-weight: bold;">,</span> <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; <span style="background-color: #3cb371;">&quot;Old Gold&quot;</span> &nbsp; &nbsp; &nbsp;<span style="color: green;">&#93;</span><br />
<span style="color: #339933; font-weight: bold;">&gt;</span> &nbsp; <span style="color: #339933; font-weight: bold;">,</span> Literal &nbsp;<span style="color: green;">&#91;</span> <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp;<span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; &nbsp;<span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; <span style="background-color: #3cb371;">&quot;Yellow&quot;</span><span style="color: #339933; font-weight: bold;">,</span> <span style="background-color: #3cb371;">&quot;Kools&quot;</span> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: green;">&#93;</span><br />
<span style="color: #339933; font-weight: bold;">&gt;</span> &nbsp; <span style="color: #339933; font-weight: bold;">,</span> Literal &nbsp;<span style="color: green;">&#91;</span> <span style="background-color: #3cb371;">&quot;3&quot;</span><span style="color: #339933; font-weight: bold;">,</span> <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; &nbsp;<span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; <span style="background-color: #3cb371;">&quot;Milk&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; <span style="background-color: #3cb371;">&quot;&quot;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: green;">&#93;</span><br />
<span style="color: #339933; font-weight: bold;">&gt;</span> &nbsp; <span style="color: #339933; font-weight: bold;">,</span> Literal &nbsp;<span style="color: green;">&#91;</span> <span style="background-color: #3cb371;">&quot;1&quot;</span><span style="color: #339933; font-weight: bold;">,</span> <span style="background-color: #3cb371;">&quot;Norway&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp;<span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; <span style="background-color: #3cb371;">&quot;&quot;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: green;">&#93;</span><br />
<span style="color: #339933; font-weight: bold;">&gt;</span> &nbsp; <span style="color: #339933; font-weight: bold;">,</span> Adjacent <span style="color: green;">&#91;</span> <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp;<span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; &nbsp;<span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; <span style="background-color: #3cb371;">&quot;Chesterfields&quot;</span> <span style="color: green;">&#93;</span><br />
<span style="color: #339933; font-weight: bold;">&gt;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: green;">&#91;</span> <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp;<span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; &nbsp;<span style="background-color: #3cb371;">&quot;Fox&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp;<span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; <span style="background-color: #3cb371;">&quot;&quot;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: green;">&#93;</span><br />
<span style="color: #339933; font-weight: bold;">&gt;</span> &nbsp; <span style="color: #339933; font-weight: bold;">,</span> Adjacent <span style="color: green;">&#91;</span> <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp;<span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; &nbsp;<span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; <span style="background-color: #3cb371;">&quot;Kools&quot;</span> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: green;">&#93;</span><br />
<span style="color: #339933; font-weight: bold;">&gt;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: green;">&#91;</span> <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp;<span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; &nbsp;<span style="background-color: #3cb371;">&quot;Horse&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp;<span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; <span style="background-color: #3cb371;">&quot;&quot;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: green;">&#93;</span><br />
<span style="color: #339933; font-weight: bold;">&gt;</span> &nbsp; <span style="color: #339933; font-weight: bold;">,</span> Literal &nbsp;<span style="color: green;">&#91;</span> <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp;<span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; &nbsp;<span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; <span style="background-color: #3cb371;">&quot;Juice&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp;<span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; <span style="background-color: #3cb371;">&quot;Lucky Strike&quot;</span> &nbsp;<span style="color: green;">&#93;</span><br />
<span style="color: #339933; font-weight: bold;">&gt;</span> &nbsp; <span style="color: #339933; font-weight: bold;">,</span> Literal &nbsp;<span style="color: green;">&#91;</span> <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp;<span style="background-color: #3cb371;">&quot;Japan&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; <span style="background-color: #3cb371;">&quot;Parliaments&quot;</span> &nbsp; <span style="color: green;">&#93;</span><br />
<span style="color: #339933; font-weight: bold;">&gt;</span> &nbsp; <span style="color: #339933; font-weight: bold;">,</span> Adjacent <span style="color: green;">&#91;</span> <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp;<span style="background-color: #3cb371;">&quot;Norway&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp;<span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; <span style="background-color: #3cb371;">&quot;&quot;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: green;">&#93;</span><br />
<span style="color: #339933; font-weight: bold;">&gt;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: green;">&#91;</span> <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp;<span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; &nbsp;<span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; <span style="background-color: #3cb371;">&quot;Blue&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; <span style="background-color: #3cb371;">&quot;&quot;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: green;">&#93;</span></div></div>
<p>Unfortunately, one drink and one animal are missing from the rules as stated, so here we just inform the solver "someone drinks water" and "someone owns a zebra"</p>
<div class="codecolorer-container haskell default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="haskell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933; font-weight: bold;">&gt;</span> &nbsp; <span style="color: #339933; font-weight: bold;">,</span> Literal &nbsp;<span style="color: green;">&#91;</span> <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp;<span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; &nbsp;<span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; <span style="background-color: #3cb371;">&quot;Water&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp;<span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; <span style="background-color: #3cb371;">&quot;&quot;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: green;">&#93;</span><br />
<span style="color: #339933; font-weight: bold;">&gt;</span> &nbsp; <span style="color: #339933; font-weight: bold;">,</span> Literal &nbsp;<span style="color: green;">&#91;</span> <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp;<span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; &nbsp;<span style="background-color: #3cb371;">&quot;Zebra&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp;<span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp; &nbsp; <span style="background-color: #3cb371;">&quot;&quot;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: green;">&#93;</span><br />
<span style="color: #339933; font-weight: bold;">&gt;</span> &nbsp; <span style="color: green;">&#93;</span></div></div>
<p>So we have three kinds of rules, for which we'll need a data definition. By now it should be self-evident how each of these work</p>
<div class="codecolorer-container haskell default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="haskell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933; font-weight: bold;">&gt;</span> <span style="color: #06c; font-weight: bold;">data</span> Rule <span style="color: #339933; font-weight: bold;">=</span> Literal &nbsp;Entry<br />
<span style="color: #339933; font-weight: bold;">&gt;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933; font-weight: bold;">|</span> Adjacent Entry Entry<br />
<span style="color: #339933; font-weight: bold;">&gt;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933; font-weight: bold;">|</span> Follows &nbsp;Entry Entry<br />
<span style="color: #339933; font-weight: bold;">&gt;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #06c; font-weight: bold;">deriving</span> <span style="color: green;">&#40;</span><a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#t:Show"><span style="color: #cccc00; font-weight: bold;">Show</span></a><span style="color: green;">&#41;</span></div></div>
<p>At this point, we have a nice, declarative specification of what a solution will look like, and we need to write the code to solve for it. The key to solving the puzzle efficiently is to realize that each rule is effectively describing some small portion of a possible answer, with empty strings representing unknown values. What we need next is a way to expand a rule into a list of all those answers that it represents</p>
<div class="codecolorer-container haskell default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="haskell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933; font-weight: bold;">&gt;</span> expandRule <span style="color: #339933; font-weight: bold;">::</span> <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#t:Int"><span style="color: #cccc00; font-weight: bold;">Int</span></a> <span style="color: #339933; font-weight: bold;">-&gt;</span> Rule <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: green;">&#91;</span>Answer<span style="color: green;">&#93;</span><br />
<span style="color: #339933; font-weight: bold;">&gt;</span> expandRule n <span style="color: green;">&#40;</span>Literal &nbsp; a <span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#91;</span> expand n <span style="color: green;">&#91;</span> a <span style="color: green;">&#93;</span> x <span style="color: #339933; font-weight: bold;">|</span> x <span style="color: #339933; font-weight: bold;">&lt;-</span> <span style="color: green;">&#91;</span><span style="color: red;">0</span> <span style="color: #339933; font-weight: bold;">..</span> n <span style="color: #339933; font-weight: bold;">-</span> <span style="color: red;">1</span><span style="color: green;">&#93;</span> <span style="color: green;">&#93;</span><br />
<span style="color: #339933; font-weight: bold;">&gt;</span> expandRule n <span style="color: green;">&#40;</span>Follows &nbsp;a b<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#91;</span> expand n <span style="color: green;">&#91;</span>a<span style="color: #339933; font-weight: bold;">,</span>b<span style="color: green;">&#93;</span> x <span style="color: #339933; font-weight: bold;">|</span> x <span style="color: #339933; font-weight: bold;">&lt;-</span> <span style="color: green;">&#91;</span><span style="color: red;">0</span> <span style="color: #339933; font-weight: bold;">..</span> n <span style="color: #339933; font-weight: bold;">-</span> <span style="color: red;">2</span><span style="color: green;">&#93;</span> <span style="color: green;">&#93;</span><br />
<span style="color: #339933; font-weight: bold;">&gt;</span> expandRule n <span style="color: green;">&#40;</span>Adjacent a b<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:concat"><span style="font-weight: bold;">concat</span></a> <span style="color: green;">&#91;</span>e <span style="color: #339933; font-weight: bold;">$</span> Follows a b<span style="color: #339933; font-weight: bold;">,</span> e <span style="color: #339933; font-weight: bold;">$</span> Follows b a<span style="color: green;">&#93;</span><br />
<span style="color: #339933; font-weight: bold;">&gt;</span> &nbsp; <span style="color: #06c; font-weight: bold;">where</span> e <span style="color: #339933; font-weight: bold;">=</span> expandRule n<br />
<span style="color: #339933; font-weight: bold;">&gt;</span><br />
<span style="color: #339933; font-weight: bold;">&gt;</span> expand <span style="color: #339933; font-weight: bold;">::</span> <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#t:Int"><span style="color: #cccc00; font-weight: bold;">Int</span></a> <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: green;">&#91;</span>Entry<span style="color: green;">&#93;</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#t:Int"><span style="color: #cccc00; font-weight: bold;">Int</span></a> <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: green;">&#91;</span>Entry<span style="color: green;">&#93;</span><br />
<span style="color: #339933; font-weight: bold;">&gt;</span> expand n rs<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> x <span style="color: #339933; font-weight: bold;">=</span> replicate x blank <span style="color: #339933; font-weight: bold;">++</span> rs <span style="color: #339933; font-weight: bold;">++</span> replicate <span style="color: green;">&#40;</span>n <span style="color: #339933; font-weight: bold;">-</span> x <span style="color: #339933; font-weight: bold;">-</span> <span style="color: red;">1</span><span style="color: green;">&#41;</span> blank<br />
<span style="color: #339933; font-weight: bold;">&gt;</span> &nbsp; <span style="color: #06c; font-weight: bold;">where</span> blank <span style="color: #339933; font-weight: bold;">=</span> replicate <span style="color: green;">&#40;</span><a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:length"><span style="font-weight: bold;">length</span></a> r<span style="color: green;">&#41;</span> <span style="background-color: #3cb371;">&quot;&quot;</span></div></div>
<p>As we go about solving the puzzle, we will at all times have a collection of answers the solver currently knows to be possible, and a set of answer fragments resulting from expanding the rule we're currently trying to satisfy. What we need is a way to test every possible combination of the old answers with the new answer fragments.</p>
<p>Our solution will make use of the nondeterminism monad, called the "list" monad by the unenlightened. As we iterate over the rules, we will expand each one in turn, test every possible combination with the old answers, and then filter out the impossible ones.</p>
<p>At first, this will cause a combinatorial explosion of possible answers, but as new rules are added, we will eventually reach a point where each additional rule manages only to decrease the number of possible solutions, until there is only one remaining.</p>
<div class="codecolorer-container haskell default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="haskell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933; font-weight: bold;">&gt;</span> applyRules <span style="color: #339933; font-weight: bold;">::</span> Answer <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: green;">&#91;</span>Rule<span style="color: green;">&#93;</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: green;">&#91;</span>Answer<span style="color: green;">&#93;</span><br />
<span style="color: #339933; font-weight: bold;">&gt;</span> applyRules answer rules <span style="color: #339933; font-weight: bold;">=</span> foldM applyRule answer rules<br />
<span style="color: #339933; font-weight: bold;">&gt;</span> &nbsp; <span style="color: #06c; font-weight: bold;">where</span> applyRule a r <span style="color: #339933; font-weight: bold;">=</span> catMaybes <span style="color: green;">&#91;</span>overlay a x <span style="color: #339933; font-weight: bold;">|</span> x <span style="color: #339933; font-weight: bold;">&lt;-</span> expandRule <span style="color: green;">&#40;</span><a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:length"><span style="font-weight: bold;">length</span></a> a<span style="color: green;">&#41;</span> r<span style="color: green;">&#93;</span></div></div>
<p>From the definition of <code class="codecolorer haskell default"><span class="haskell">applyRules</span></code>, it is clear that our overlay operation needs to have type <code class="codecolorer haskell default"><span class="haskell">Answer <span style="color: #339933; font-weight: bold;">-&gt;</span> Answer <span style="color: #339933; font-weight: bold;">-&gt;</span> <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#t:Maybe"><span style="color: #cccc00; font-weight: bold;">Maybe</span></a> Answer</span></code>. If any two answers are both defined and different from each other, we return <code class="codecolorer haskell default"><span class="haskell">Nothing</span></code>, and otherwise we return the most defined of the two fields.</p>
<div class="codecolorer-container haskell default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="haskell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933; font-weight: bold;">&gt;</span> overlay <span style="color: #339933; font-weight: bold;">::</span> Answer <span style="color: #339933; font-weight: bold;">-&gt;</span> Answer <span style="color: #339933; font-weight: bold;">-&gt;</span> <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#t:Maybe"><span style="color: #cccc00; font-weight: bold;">Maybe</span></a> Answer<br />
<span style="color: #339933; font-weight: bold;">&gt;</span> overlay old new <span style="color: #339933; font-weight: bold;">=</span> <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:sequence"><span style="font-weight: bold;">sequence</span></a> <span style="color: #339933; font-weight: bold;">$</span> <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:zipWith"><span style="font-weight: bold;">zipWith</span></a> overlay' old new<br />
<span style="color: #339933; font-weight: bold;">&gt;</span> &nbsp; <span style="color: #06c; font-weight: bold;">where</span> overlay' old new <span style="color: #339933; font-weight: bold;">=</span> <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:sequence"><span style="font-weight: bold;">sequence</span></a> <span style="color: #339933; font-weight: bold;">$</span> <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:zipWith"><span style="font-weight: bold;">zipWith</span></a> overlay'' old new<br />
<span style="color: #339933; font-weight: bold;">&gt;</span> &nbsp; &nbsp; &nbsp; &nbsp; overlay'' <span style="background-color: #3cb371;">&quot;&quot;</span> <span style="background-color: #3cb371;">&quot;&quot;</span> &nbsp;<span style="color: #339933; font-weight: bold;">=</span> Just <span style="background-color: #3cb371;">&quot;&quot;</span><br />
<span style="color: #339933; font-weight: bold;">&gt;</span> &nbsp; &nbsp; &nbsp; &nbsp; overlay'' <span style="background-color: #3cb371;">&quot;&quot;</span> n &nbsp; <span style="color: #339933; font-weight: bold;">=</span> Just n<br />
<span style="color: #339933; font-weight: bold;">&gt;</span> &nbsp; &nbsp; &nbsp; &nbsp; overlay'' o &nbsp;<span style="background-color: #3cb371;">&quot;&quot;</span> &nbsp;<span style="color: #339933; font-weight: bold;">=</span> Just o<br />
<span style="color: #339933; font-weight: bold;">&gt;</span> &nbsp; &nbsp; &nbsp; &nbsp; overlay'' o &nbsp;n<br />
<span style="color: #339933; font-weight: bold;">&gt;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933; font-weight: bold;">|</span> o <span style="color: #339933; font-weight: bold;">==</span> n &nbsp; &nbsp; &nbsp; <span style="color: #339933; font-weight: bold;">=</span> Just o<br />
<span style="color: #339933; font-weight: bold;">&gt;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933; font-weight: bold;">|</span> <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:otherwise"><span style="font-weight: bold;">otherwise</span></a> &nbsp; &nbsp;<span style="color: #339933; font-weight: bold;">=</span> Nothing</div></div>
<p>Before any constraints are applied, the answer is entirely undefined, so the process of solving consists simply of applying all the rules to an initial empty answer, and seeing what results. In this case, there is only one answer, but removing one or more rules from the list can make other solutions equally valid.</p>
<div class="codecolorer-container haskell default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="haskell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933; font-weight: bold;">&gt;</span> main <span style="color: #339933; font-weight: bold;">=</span> showAnswers <span style="color: #339933; font-weight: bold;">.</span> applyRules emptyAnswer <span style="color: #339933; font-weight: bold;">$</span> rules<br />
<span style="color: #339933; font-weight: bold;">&gt;</span> &nbsp; <span style="color: #06c; font-weight: bold;">where</span> emptyAnswer <span style="color: #339933; font-weight: bold;">=</span> replicate <span style="color: red;">5</span> <span style="color: #339933; font-weight: bold;">.</span> replicate <span style="color: red;">6</span> <span style="color: #339933; font-weight: bold;">$</span> <span style="background-color: #3cb371;">&quot;&quot;</span><br />
<span style="color: #339933; font-weight: bold;">&gt;</span> &nbsp; &nbsp; &nbsp; &nbsp; showAnswers <span style="color: #339933; font-weight: bold;">=</span> <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:mapM_"><span style="font-weight: bold;">mapM_</span></a> <span style="color: #339933; font-weight: bold;">$</span> <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:mapM_"><span style="font-weight: bold;">mapM_</span></a> <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:print"><span style="font-weight: bold;">print</span></a></div></div>
<p>To see how each additional rule changes the set of possible answers, you can try something like "<code class="codecolorer haskell default"><span class="haskell"><a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:mapM_"><span style="font-weight: bold;">mapM_</span></a> <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:print"><span style="font-weight: bold;">print</span></a> <span style="color: #339933; font-weight: bold;">.</span> applyRules emptyAnswer <span style="color: #339933; font-weight: bold;">.</span> <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:take"><span style="font-weight: bold;">take</span></a> ## <span style="color: #339933; font-weight: bold;">$</span> rules</span></code>" in GHCi, for all the numbers between 1 and 20.</p>
<p>(This post is Literate Haskell, meaning that it can be copied and pasted in its entirety into a <code class="codecolorer text default"><span class="text">*.lhs</span></code> file, and then run with <code class="codecolorer text default"><span class="text">runhaskell</span></code>)</p>
<script type="text/javascript">
var flattr_wp_ver = '0.9.11';
var flattr_uid = '19057';
var flattr_url = 'http://blog.willdonnelly.net';
var flattr_lng = 'en_GB';
var flattr_cat = 'text';
var flattr_tag = 'blog,wordpress,rss,feed';
var flattr_btn = 'large';
var flattr_tle = 'It Seemed Like a Good Idea at the Time';
var flattr_dsc = 'Coding, Mostly';
</script>
<script src="http://api.flattr.com/button/load.js?v=0.2" type="text/javascript"></script><div class="lightsocial_container"><a class="lightsocial_a" href="http://digg.com/submit?url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F11%2F06%2Fsolving-logic-grid-puzzles-in-haskell%2F&amp;title=Solving+Logic+Grid+Puzzles+in+Haskell" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/digg.png" alt="Digg This" title="Digg This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.reddit.com/submit?url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F11%2F06%2Fsolving-logic-grid-puzzles-in-haskell%2F&amp;title=Solving+Logic+Grid+Puzzles+in+Haskell" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/reddit.png" alt="Reddit This" title="Reddit This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F11%2F06%2Fsolving-logic-grid-puzzles-in-haskell%2F&amp;title=Solving+Logic+Grid+Puzzles+in+Haskell" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/stumbleupon.png" alt="Stumble Now!" title="Stumble Now!" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://buzz.yahoo.com/buzz?targetUrl=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F11%2F06%2Fsolving-logic-grid-puzzles-in-haskell%2F&amp;headline=Solving+Logic+Grid+Puzzles+in+Haskell" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/yahoo_buzz.png" alt="Buzz This" title="Buzz This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dzone.com/links/add.html?title=Solving+Logic+Grid+Puzzles+in+Haskell&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F11%2F06%2Fsolving-logic-grid-puzzles-in-haskell%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/dzone.png" alt="Vote on DZone" title="Vote on DZone" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.facebook.com/sharer.php?t=Solving+Logic+Grid+Puzzles+in+Haskell&amp;u=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F11%2F06%2Fsolving-logic-grid-puzzles-in-haskell%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/facebook.png" alt="Share on Facebook" title="Share on Facebook" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://delicious.com/save?title=Solving+Logic+Grid+Puzzles+in+Haskell&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F11%2F06%2Fsolving-logic-grid-puzzles-in-haskell%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/delicious.png" alt="Bookmark this on Delicious" title="Bookmark this on Delicious" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dotnetkicks.com/kick/?title=Solving+Logic+Grid+Puzzles+in+Haskell&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F11%2F06%2Fsolving-logic-grid-puzzles-in-haskell%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/dotnetkicks.png" alt="Kick It on DotNetKicks.com" title="Kick It on DotNetKicks.com" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://dotnetshoutout.com/Submit?title=Solving+Logic+Grid+Puzzles+in+Haskell&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F11%2F06%2Fsolving-logic-grid-puzzles-in-haskell%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/dotnetshoutout.png" alt="Shout it" title="Shout it" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F11%2F06%2Fsolving-logic-grid-puzzles-in-haskell%2F&amp;title=Solving+Logic+Grid+Puzzles+in+Haskell&amp;summary=&amp;source=" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/linkedin.png" alt="Share on LinkedIn" title="Share on LinkedIn" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.technorati.com/faves?add=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F11%2F06%2Fsolving-logic-grid-puzzles-in-haskell%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/technorati.png" alt="Bookmark this on Technorati" title="Bookmark this on Technorati" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://twitter.com/home?status=Reading+http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F11%2F06%2Fsolving-logic-grid-puzzles-in-haskell%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/twitter.png" alt="Post on Twitter" title="Post on Twitter" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.google.com/buzz/post?url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F11%2F06%2Fsolving-logic-grid-puzzles-in-haskell%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/google_buzz.png" alt="Google Buzz (aka. Google Reader)" title="Google Buzz (aka. Google Reader)" /></a>&nbsp;&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://blog.willdonnelly.net/2009/11/06/solving-logic-grid-puzzles-in-haskell/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Brian&#8217;s (Purely) Functional Brain</title>
		<link>http://blog.willdonnelly.net/2009/10/14/brians-purely-functional-brain/</link>
		<comments>http://blog.willdonnelly.net/2009/10/14/brians-purely-functional-brain/#comments</comments>
		<pubDate>Thu, 15 Oct 2009 02:16:39 +0000</pubDate>
		<dc:creator>Will Donnelly</dc:creator>
				<category><![CDATA[haskell]]></category>
		<category><![CDATA[anythingyoucandohaskellcandobetter]]></category>
		<category><![CDATA[brians brain]]></category>

		<guid isPermaLink="false">http://blog.willdonnelly.net/?p=293</guid>
		<description><![CDATA[So about a week ago I came across an interesting post i [...]]]></description>
			<content:encoded><![CDATA[<p>So about a week ago I came across <a href="http://blog.bestinclass.dk/index.php/2009/10/brians-functional-brain/">an interesting post</a> in which the author implemented the <a href="http://en.wikipedia.org/wiki/Brian's_Brain">Brian's Brain</a> cellular automaton in 67 lines of Clojure. Not about to let <a title="Haskell: My Language Can Beat Up Your Language" href="http://haskell.org/">my favorite language</a> be outdone, I thought I'd see how well Haskell would do with the same task.</p>
<p>Then I was kept horribly busy for a week by schoolwork, so a couple of days ago I started playing around with the problem. The results? Not too shabby!</p>
<p>So first of all, we'll be needing some imports. Since (for some odd reason) Haskell requires all imports up front, and since this blog post is supposed to be <a href="http://www.haskell.org/haskellwiki/Literate_programming">Literate Haskell</a>, you'll have to just trust me that we'll need these for now:</p>
<div class="codecolorer-container haskell default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="haskell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933; font-weight: bold;">&gt;</span> <span style="color: #06c; font-weight: bold;">import</span> Data<span style="color: #339933; font-weight: bold;">.</span>Array &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #5d478b; font-style: italic;">-- Used to store the world state for processing</span><br />
<span style="color: #339933; font-weight: bold;">&gt;</span> <span style="color: #06c; font-weight: bold;">import</span> System<span style="color: #339933; font-weight: bold;">.</span>Random &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #5d478b; font-style: italic;">-- Used to generate the initial random world</span><br />
<span style="color: #339933; font-weight: bold;">&gt;</span> <span style="color: #06c; font-weight: bold;">import</span> Control<span style="color: #339933; font-weight: bold;">.</span><a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#t:Monad"><span style="color: #cccc00; font-weight: bold;">Monad</span></a> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #5d478b; font-style: italic;">-- Used for some fancy looping constructs</span><br />
<span style="color: #339933; font-weight: bold;">&gt;</span> <span style="color: #06c; font-weight: bold;">import</span> Control<span style="color: #339933; font-weight: bold;">.</span>Concurrent &nbsp; &nbsp; <span style="color: #5d478b; font-style: italic;">-- Used to fork the quit event handler</span><br />
<span style="color: #339933; font-weight: bold;">&gt;</span> <span style="color: #06c; font-weight: bold;">import</span> Graphics<span style="color: #339933; font-weight: bold;">.</span>UI<span style="color: #339933; font-weight: bold;">.</span>SDL <span style="color: #06c; font-weight: bold;">as</span> SDL <span style="color: #5d478b; font-style: italic;">-- Used to draw the pretty pictures</span><br />
<span style="color: #339933; font-weight: bold;">&gt;</span> <span style="color: #06c; font-weight: bold;">import</span> Control<span style="color: #339933; font-weight: bold;">.</span>Parallel<span style="color: #339933; font-weight: bold;">.</span>Strategies</div></div>
<p>Cells can be either On, Dying, or Off:</p>
<div class="codecolorer-container haskell default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="haskell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933; font-weight: bold;">&gt;</span> <span style="color: #06c; font-weight: bold;">data</span> Cell &nbsp;<span style="color: #339933; font-weight: bold;">=</span> Off <span style="color: #339933; font-weight: bold;">|</span> Dying <span style="color: #339933; font-weight: bold;">|</span> On <span style="color: #06c; font-weight: bold;">deriving</span> <span style="color: green;">&#40;</span><a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#t:Eq"><span style="color: #cccc00; font-weight: bold;">Eq</span></a><span style="color: #339933; font-weight: bold;">,</span> <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#t:Enum"><span style="color: #cccc00; font-weight: bold;">Enum</span></a><span style="color: green;">&#41;</span></div></div>
<p>For convenience, let's define some constants:</p>
<div class="codecolorer-container haskell default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="haskell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933; font-weight: bold;">&gt;</span> worldX &nbsp; <span style="color: #339933; font-weight: bold;">=</span> <span style="color: red;">90</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #5d478b; font-style: italic;">-- The horizontal size of the world</span><br />
<span style="color: #339933; font-weight: bold;">&gt;</span> worldY &nbsp; <span style="color: #339933; font-weight: bold;">=</span> <span style="color: red;">90</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #5d478b; font-style: italic;">-- The vertical size of the world</span><br />
<span style="color: #339933; font-weight: bold;">&gt;</span> cellSize <span style="color: #339933; font-weight: bold;">=</span> <span style="color: red;">8</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #5d478b; font-style: italic;">-- The overall size of a cell</span><br />
<span style="color: #339933; font-weight: bold;">&gt;</span> border &nbsp; <span style="color: #339933; font-weight: bold;">=</span> <span style="color: red;">1</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #5d478b; font-style: italic;">-- The border width between cells</span><br />
<span style="color: #339933; font-weight: bold;">&gt;</span> screenX &nbsp;<span style="color: #339933; font-weight: bold;">=</span> worldX <span style="color: #339933; font-weight: bold;">*</span> cellSize <span style="color: #5d478b; font-style: italic;">-- The horizontal size of the world, in pixels</span><br />
<span style="color: #339933; font-weight: bold;">&gt;</span> screenY &nbsp;<span style="color: #339933; font-weight: bold;">=</span> worldY <span style="color: #339933; font-weight: bold;">*</span> cellSize <span style="color: #5d478b; font-style: italic;">-- The vertical size of the world, in pixels</span><br />
<span style="color: #339933; font-weight: bold;">&gt;</span> fillSize <span style="color: #339933; font-weight: bold;">=</span> cellSize <span style="color: #339933; font-weight: bold;">-</span> border <span style="color: #5d478b; font-style: italic;">-- The size of the filled area in each cell</span></div></div>
<p>Cells progress from On to Dying to Off, and they turn on only when they have exactly two live neighbors.</p>
<div class="codecolorer-container haskell default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="haskell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933; font-weight: bold;">&gt;</span> stepCell <span style="color: green;">&#40;</span>On<span style="color: #339933; font-weight: bold;">,</span> &nbsp; &nbsp;<span style="color: #339933; font-weight: bold;">_</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> Dying &nbsp;<span style="color: #5d478b; font-style: italic;">-- Live cells always start to die</span><br />
<span style="color: #339933; font-weight: bold;">&gt;</span> stepCell <span style="color: green;">&#40;</span>Dying<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> Off &nbsp; &nbsp;<span style="color: #5d478b; font-style: italic;">-- Dying cells always turn off</span><br />
<span style="color: #339933; font-weight: bold;">&gt;</span> stepCell <span style="color: green;">&#40;</span>Off<span style="color: #339933; font-weight: bold;">,</span> &nbsp; <span style="color: red;">2</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> On &nbsp; &nbsp; <span style="color: #5d478b; font-style: italic;">-- If a dead cell has 2 live neighbors, turn on</span><br />
<span style="color: #339933; font-weight: bold;">&gt;</span> stepCell <span style="color: green;">&#40;</span>Off<span style="color: #339933; font-weight: bold;">,</span> &nbsp; <span style="color: #339933; font-weight: bold;">_</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> Off &nbsp; &nbsp;<span style="color: #5d478b; font-style: italic;">-- &nbsp; Otherwise, just stay turned off</span></div></div>
<p>Since we know from the rules that we'll need the ability to count a cell's live neighbors, let's get that out of the way next.</p>
<div class="codecolorer-container haskell default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="haskell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933; font-weight: bold;">&gt;</span> getPeers world <span style="color: green;">&#40;</span>x<span style="color: #339933; font-weight: bold;">,</span>y<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#40;</span>world <span style="color: #339933; font-weight: bold;">!</span> <span style="color: green;">&#40;</span>x<span style="color: #339933; font-weight: bold;">,</span>y<span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:length"><span style="font-weight: bold;">length</span></a> <span style="color: #339933; font-weight: bold;">.</span> <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:filter"><span style="font-weight: bold;">filter</span></a> <span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">==</span> On<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">$</span> neighbors<span style="color: green;">&#41;</span><br />
<span style="color: #339933; font-weight: bold;">&gt;</span> &nbsp; <span style="color: #06c; font-weight: bold;">where</span> neighbors &nbsp; &nbsp;<span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#91;</span>getCell x y <span style="color: #339933; font-weight: bold;">|</span> x <span style="color: #339933; font-weight: bold;">&lt;-</span> <span style="color: green;">&#91;</span>x<span style="color: #339933; font-weight: bold;">-</span><span style="color: red;">1</span> <span style="color: #339933; font-weight: bold;">..</span> x<span style="color: #339933; font-weight: bold;">+</span><span style="color: red;">1</span><span style="color: green;">&#93;</span><span style="color: #339933; font-weight: bold;">,</span> y <span style="color: #339933; font-weight: bold;">&lt;-</span> <span style="color: green;">&#91;</span>y<span style="color: #339933; font-weight: bold;">-</span><span style="color: red;">1</span> <span style="color: #339933; font-weight: bold;">..</span> y<span style="color: #339933; font-weight: bold;">+</span><span style="color: red;">1</span><span style="color: green;">&#93;</span><span style="color: green;">&#93;</span><br />
<span style="color: #339933; font-weight: bold;">&gt;</span> &nbsp; &nbsp; &nbsp; &nbsp; getCell x y &nbsp;<span style="color: #339933; font-weight: bold;">=</span> world <span style="color: #339933; font-weight: bold;">!</span> <span style="color: green;">&#40;</span>clip worldX x<span style="color: #339933; font-weight: bold;">,</span> clip worldY y<span style="color: green;">&#41;</span><br />
<span style="color: #339933; font-weight: bold;">&gt;</span> &nbsp; &nbsp; &nbsp; &nbsp; clip <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:max"><span style="font-weight: bold;">max</span></a> val <span style="color: #339933; font-weight: bold;">|</span> val <span style="color: #339933; font-weight: bold;">&lt;</span> &nbsp;<span style="color: red;">1</span> &nbsp;<span style="color: #339933; font-weight: bold;">=</span> clip <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:max"><span style="font-weight: bold;">max</span></a> <span style="color: #339933; font-weight: bold;">$</span> val <span style="color: #339933; font-weight: bold;">+</span> <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:max"><span style="font-weight: bold;">max</span></a> <span style="color: #339933; font-weight: bold;">-</span> <span style="color: red;">1</span><br />
<span style="color: #339933; font-weight: bold;">&gt;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #339933; font-weight: bold;">|</span> val <span style="color: #339933; font-weight: bold;">&gt;</span> <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:max"><span style="font-weight: bold;">max</span></a> <span style="color: #339933; font-weight: bold;">=</span> clip <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:max"><span style="font-weight: bold;">max</span></a> <span style="color: #339933; font-weight: bold;">$</span> val <span style="color: #339933; font-weight: bold;">-</span> <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:max"><span style="font-weight: bold;">max</span></a> <span style="color: #339933; font-weight: bold;">+</span> <span style="color: red;">1</span><br />
<span style="color: #339933; font-weight: bold;">&gt;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #339933; font-weight: bold;">|</span> <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:otherwise"><span style="font-weight: bold;">otherwise</span></a> <span style="color: #339933; font-weight: bold;">=</span> val</div></div>
<p>So now we have all the pieces to progress from one world state to the next. For each position in the array, we need to look up all its neighbors, count the live ones, and then pass that data to the <code class="codecolorer text default"><span class="text">stepCell</span></code> function. The helper function <code class="codecolorer text default"><span class="text">indexArray</span></code> creates an array of cell indices. We map over this array to generate new values for each cell.</p>
<p>The <code class="codecolorer haskell default"><span class="haskell">`using` parArr rwhnf</span></code>  is some Haskell magic which causes the array to be evaluated in parallel:</p>
<div class="codecolorer-container haskell default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="haskell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933; font-weight: bold;">&gt;</span> indexArray x y <span style="color: #339933; font-weight: bold;">=</span> listArray <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span><span style="color: red;">1</span><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><span style="color: green;">&#40;</span>x<span style="color: #339933; font-weight: bold;">,</span>y<span style="color: green;">&#41;</span><span style="color: green;">&#41;</span> <span style="color: green;">&#91;</span><span style="color: green;">&#40;</span>a<span style="color: #339933; font-weight: bold;">,</span>b<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">|</span> a <span style="color: #339933; font-weight: bold;">&lt;-</span> <span style="color: green;">&#91;</span><span style="color: red;">1</span><span style="color: #339933; font-weight: bold;">..</span>x<span style="color: green;">&#93;</span><span style="color: #339933; font-weight: bold;">,</span> b <span style="color: #339933; font-weight: bold;">&lt;-</span> <span style="color: green;">&#91;</span><span style="color: red;">1</span><span style="color: #339933; font-weight: bold;">..</span>y<span style="color: green;">&#93;</span><span style="color: green;">&#93;</span><br />
<span style="color: #339933; font-weight: bold;">&gt;</span> stepWorld w &nbsp; &nbsp;<span style="color: #339933; font-weight: bold;">=</span> newWorld `using` parArr rwhnf<br />
<span style="color: #339933; font-weight: bold;">&gt;</span> &nbsp; <span style="color: #06c; font-weight: bold;">where</span> newWorld <span style="color: #339933; font-weight: bold;">=</span> <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:fmap"><span style="font-weight: bold;">fmap</span></a> <span style="color: green;">&#40;</span>stepCell <span style="color: #339933; font-weight: bold;">.</span> getPeers w<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">$</span> indexArray worldX worldY</div></div>
<p>Now we have all we need to run a simulation, but it's not quite enough if you insist on getting some pretty pictures. For my fancy display purposes, I happen to like SDL.</p>
<p>The main function initializes SDL, generates a random initial state, produces an infinite list of future world states from that, and then draws each of the states in turn:</p>
<div class="codecolorer-container haskell default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="haskell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933; font-weight: bold;">&gt;</span> main <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">do</span> rng <span style="color: #339933; font-weight: bold;">&lt;-</span> newStdGen<br />
<span style="color: #339933; font-weight: bold;">&gt;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SDL<span style="color: #339933; font-weight: bold;">.</span><a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:init"><span style="font-weight: bold;">init</span></a> <span style="color: green;">&#91;</span>SDL<span style="color: #339933; font-weight: bold;">.</span>InitVideo<span style="color: green;">&#93;</span><br />
<span style="color: #339933; font-weight: bold;">&gt;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SDL<span style="color: #339933; font-weight: bold;">.</span>setCaption <span style="background-color: #3cb371;">&quot;Brian's Purely Functional Brain&quot;</span> <span style="background-color: #3cb371;">&quot;Brian's Brain&quot;</span><br />
<span style="color: #339933; font-weight: bold;">&gt;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; surface <span style="color: #339933; font-weight: bold;">&lt;-</span> SDL<span style="color: #339933; font-weight: bold;">.</span>setVideoMode screenX screenY <span style="color: red;">24</span> <span style="color: green;">&#91;</span>SDL<span style="color: #339933; font-weight: bold;">.</span>DoubleBuf<span style="color: green;">&#93;</span><br />
<span style="color: #339933; font-weight: bold;">&gt;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; forkIO <span style="color: #339933; font-weight: bold;">.</span> forever <span style="color: #339933; font-weight: bold;">$</span> waitEvent <span style="color: #339933; font-weight: bold;">&gt;&gt;=</span> \e <span style="color: #339933; font-weight: bold;">-&gt;</span> when <span style="color: green;">&#40;</span>e <span style="color: #339933; font-weight: bold;">==</span> Quit<span style="color: green;">&#41;</span> quit<br />
<span style="color: #339933; font-weight: bold;">&gt;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:mapM"><span style="font-weight: bold;">mapM</span></a> <span style="color: green;">&#40;</span>drawWorld surface<span style="color: green;">&#41;</span> <span style="color: green;">&#40;</span><a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:iterate"><span style="font-weight: bold;">iterate</span></a> stepWorld <span style="color: #339933; font-weight: bold;">$</span> world rng<span style="color: green;">&#41;</span><br />
<span style="color: #339933; font-weight: bold;">&gt;</span> &nbsp; <span style="color: #06c; font-weight: bold;">where</span> world <span style="color: #339933; font-weight: bold;">=</span> listArray <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span><span style="color: red;">1</span><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><span style="color: green;">&#40;</span>worldX<span style="color: #339933; font-weight: bold;">,</span>worldY<span style="color: green;">&#41;</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">.</span> <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:map"><span style="font-weight: bold;">map</span></a> <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:toEnum"><span style="font-weight: bold;">toEnum</span></a> <span style="color: #339933; font-weight: bold;">.</span> randomRs <span style="color: green;">&#40;</span><span style="color: red;">0</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">2</span><span style="color: green;">&#41;</span></div></div>
<p>And our world drawing function is positively boring. We map over each combination of X and Y values, draw each one, and then flip the resulting image on-screen:</p>
<div class="codecolorer-container haskell default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="haskell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933; font-weight: bold;">&gt;</span> drawWorld s w <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">do</span> <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:sequence"><span style="font-weight: bold;">sequence</span></a> <span style="color: green;">&#91;</span>draw x y <span style="color: #339933; font-weight: bold;">|</span> x <span style="color: #339933; font-weight: bold;">&lt;-</span> <span style="color: green;">&#91;</span><span style="color: red;">1</span><span style="color: #339933; font-weight: bold;">..</span>worldX<span style="color: green;">&#93;</span><span style="color: #339933; font-weight: bold;">,</span> y <span style="color: #339933; font-weight: bold;">&lt;-</span> <span style="color: green;">&#91;</span><span style="color: red;">1</span><span style="color: #339933; font-weight: bold;">..</span>worldY<span style="color: green;">&#93;</span><span style="color: green;">&#93;</span><br />
<span style="color: #339933; font-weight: bold;">&gt;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SDL<span style="color: #339933; font-weight: bold;">.</span><a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:flip"><span style="font-weight: bold;">flip</span></a> s<br />
<span style="color: #339933; font-weight: bold;">&gt;</span> &nbsp; <span style="color: #06c; font-weight: bold;">where</span> draw x y <span style="color: #339933; font-weight: bold;">=</span> SDL<span style="color: #339933; font-weight: bold;">.</span>fillRect s <span style="color: green;">&#40;</span>Just rect<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">.</span> color <span style="color: #339933; font-weight: bold;">$</span> w <span style="color: #339933; font-weight: bold;">!</span> <span style="color: green;">&#40;</span>x<span style="color: #339933; font-weight: bold;">,</span>y<span style="color: green;">&#41;</span><br />
<span style="color: #339933; font-weight: bold;">&gt;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #06c; font-weight: bold;">where</span> rect &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #339933; font-weight: bold;">=</span> SDL<span style="color: #339933; font-weight: bold;">.</span>Rect <span style="color: green;">&#40;</span>scale x<span style="color: green;">&#41;</span> <span style="color: green;">&#40;</span>scale y<span style="color: green;">&#41;</span> fillSize fillSize<br />
<span style="color: #339933; font-weight: bold;">&gt;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; scale n &nbsp; &nbsp; <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#40;</span>n <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> cellSize<br />
<span style="color: #339933; font-weight: bold;">&gt;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; color On &nbsp; &nbsp;<span style="color: #339933; font-weight: bold;">=</span> SDL<span style="color: #339933; font-weight: bold;">.</span>Pixel 0x00FFFFFF<br />
<span style="color: #339933; font-weight: bold;">&gt;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; color Dying <span style="color: #339933; font-weight: bold;">=</span> SDL<span style="color: #339933; font-weight: bold;">.</span>Pixel 0x00888888<br />
<span style="color: #339933; font-weight: bold;">&gt;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; color Off &nbsp; <span style="color: #339933; font-weight: bold;">=</span> SDL<span style="color: #339933; font-weight: bold;">.</span>Pixel 0x00000000</div></div>
<p>To take full advantage of the parallelism in this program, you'll need to compile with the threaded runtime and run it on multiple OS threads.</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">ghc -O3 -threaded --make BriansBrain.hs<br />
./BriansBrain +RTS -N2</div></div>
<p>And then just sit back and watch the mesmerising patterns.</p>
<p>This code is available on <a href="http://hackage.haskell.org/package/brians-brain">Hackage</a> and <a href="http://github.com/willdonnelly/brians-brain">GitHub</a>.</p>
<div id="attachment_349" class="wp-caption alignnone" style="width: 310px"><a href="http://blog.willdonnelly.net/wp-content/uploads/brians-brain.png"><img class="size-medium wp-image-349" title="Brian's Purely Functional Brain" src="http://blog.willdonnelly.net/wp-content/uploads/brians-brain-300x187.png" alt="" width="300" height="187" /></a><p class="wp-caption-text">Pretty Colors</p></div>
<div class="lightsocial_container"><a class="lightsocial_a" href="http://digg.com/submit?url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F10%2F14%2Fbrians-purely-functional-brain%2F&amp;title=Brian%27s+%28Purely%29+Functional+Brain" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/digg.png" alt="Digg This" title="Digg This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.reddit.com/submit?url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F10%2F14%2Fbrians-purely-functional-brain%2F&amp;title=Brian%27s+%28Purely%29+Functional+Brain" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/reddit.png" alt="Reddit This" title="Reddit This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F10%2F14%2Fbrians-purely-functional-brain%2F&amp;title=Brian%27s+%28Purely%29+Functional+Brain" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/stumbleupon.png" alt="Stumble Now!" title="Stumble Now!" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://buzz.yahoo.com/buzz?targetUrl=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F10%2F14%2Fbrians-purely-functional-brain%2F&amp;headline=Brian%27s+%28Purely%29+Functional+Brain" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/yahoo_buzz.png" alt="Buzz This" title="Buzz This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dzone.com/links/add.html?title=Brian%27s+%28Purely%29+Functional+Brain&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F10%2F14%2Fbrians-purely-functional-brain%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/dzone.png" alt="Vote on DZone" title="Vote on DZone" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.facebook.com/sharer.php?t=Brian%27s+%28Purely%29+Functional+Brain&amp;u=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F10%2F14%2Fbrians-purely-functional-brain%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/facebook.png" alt="Share on Facebook" title="Share on Facebook" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://delicious.com/save?title=Brian%27s+%28Purely%29+Functional+Brain&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F10%2F14%2Fbrians-purely-functional-brain%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/delicious.png" alt="Bookmark this on Delicious" title="Bookmark this on Delicious" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dotnetkicks.com/kick/?title=Brian%27s+%28Purely%29+Functional+Brain&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F10%2F14%2Fbrians-purely-functional-brain%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/dotnetkicks.png" alt="Kick It on DotNetKicks.com" title="Kick It on DotNetKicks.com" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://dotnetshoutout.com/Submit?title=Brian%27s+%28Purely%29+Functional+Brain&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F10%2F14%2Fbrians-purely-functional-brain%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/dotnetshoutout.png" alt="Shout it" title="Shout it" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F10%2F14%2Fbrians-purely-functional-brain%2F&amp;title=Brian%27s+%28Purely%29+Functional+Brain&amp;summary=&amp;source=" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/linkedin.png" alt="Share on LinkedIn" title="Share on LinkedIn" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.technorati.com/faves?add=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F10%2F14%2Fbrians-purely-functional-brain%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/technorati.png" alt="Bookmark this on Technorati" title="Bookmark this on Technorati" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://twitter.com/home?status=Reading+http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F10%2F14%2Fbrians-purely-functional-brain%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/twitter.png" alt="Post on Twitter" title="Post on Twitter" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.google.com/buzz/post?url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F10%2F14%2Fbrians-purely-functional-brain%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/google_buzz.png" alt="Google Buzz (aka. Google Reader)" title="Google Buzz (aka. Google Reader)" /></a>&nbsp;&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://blog.willdonnelly.net/2009/10/14/brians-purely-functional-brain/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>Haskell While Loop</title>
		<link>http://blog.willdonnelly.net/2009/09/15/haskell-while-loop/</link>
		<comments>http://blog.willdonnelly.net/2009/09/15/haskell-while-loop/#comments</comments>
		<pubDate>Wed, 16 Sep 2009 02:48:44 +0000</pubDate>
		<dc:creator>Will Donnelly</dc:creator>
				<category><![CDATA[haskell]]></category>

		<guid isPermaLink="false">http://blog.willdonnelly.net/?p=285</guid>
		<description><![CDATA[In the past week, while working on three completely unr [...]]]></description>
			<content:encoded><![CDATA[<p>In the past week, while working on three completely unrelated Haskell projects, I have found myself in need of a while loop. So I came up with this one:</p>
<div class="codecolorer-container haskell default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="haskell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #5d478b; font-style: italic;">-- | For some reason Control.Monad doesn't provide a 'while'</span><br />
<span style="color: #5d478b; font-style: italic;">-- &nbsp; function, even though it has a 'forever' function.</span><br />
while <span style="color: #339933; font-weight: bold;">::</span> <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#t:Monad"><span style="color: #cccc00; font-weight: bold;">Monad</span></a> m <span style="color: #339933; font-weight: bold;">=&gt;</span> m <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#t:Bool"><span style="color: #cccc00; font-weight: bold;">Bool</span></a> <span style="color: #339933; font-weight: bold;">-&gt;</span> m a <span style="color: #339933; font-weight: bold;">-&gt;</span> m <span style="color: green;">&#40;</span><span style="color: green;">&#41;</span><br />
while predicate action <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">do</span><br />
&nbsp; &nbsp; b <span style="color: #339933; font-weight: bold;">&lt;-</span> predicate<br />
&nbsp; &nbsp; <span style="color: #06c; font-weight: bold;">if</span> b <span style="color: #06c; font-weight: bold;">then</span> action <span style="color: #339933; font-weight: bold;">&gt;&gt;</span> while predicate action<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #06c; font-weight: bold;">else</span> <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:return"><span style="font-weight: bold;">return</span></a> <span style="color: green;">&#40;</span><span style="color: green;">&#41;</span></div></div>
<p>Hoogle shows no functions with that type signature, and I couldn't find anything in the documentation that seemed to fit the bill. This seems like a rather fundamental function for getting stuff done, is there something I'm missing?</p>
<p>EDIT: The most code-golfed version I have yet come up with is <code class="codecolorer haskell default"><span class="haskell">while p a <span style="color: #339933; font-weight: bold;">=</span> p <span style="color: #339933; font-weight: bold;">&gt;&gt;=</span> <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:flip"><span style="font-weight: bold;">flip</span></a> when <span style="color: green;">&#40;</span>a <span style="color: #339933; font-weight: bold;">&gt;&gt;</span> while p a<span style="color: green;">&#41;</span></span></code> can anyone improve on that?</p>
<script type="text/javascript">
var flattr_wp_ver = '0.9.11';
var flattr_uid = '19057';
var flattr_url = 'http://blog.willdonnelly.net';
var flattr_lng = 'en_GB';
var flattr_cat = 'text';
var flattr_tag = 'blog,wordpress,rss,feed';
var flattr_btn = 'large';
var flattr_tle = 'It Seemed Like a Good Idea at the Time';
var flattr_dsc = 'Coding, Mostly';
</script>
<script src="http://api.flattr.com/button/load.js?v=0.2" type="text/javascript"></script><div class="lightsocial_container"><a class="lightsocial_a" href="http://digg.com/submit?url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F09%2F15%2Fhaskell-while-loop%2F&amp;title=Haskell+While+Loop" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/digg.png" alt="Digg This" title="Digg This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.reddit.com/submit?url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F09%2F15%2Fhaskell-while-loop%2F&amp;title=Haskell+While+Loop" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/reddit.png" alt="Reddit This" title="Reddit This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F09%2F15%2Fhaskell-while-loop%2F&amp;title=Haskell+While+Loop" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/stumbleupon.png" alt="Stumble Now!" title="Stumble Now!" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://buzz.yahoo.com/buzz?targetUrl=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F09%2F15%2Fhaskell-while-loop%2F&amp;headline=Haskell+While+Loop" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/yahoo_buzz.png" alt="Buzz This" title="Buzz This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dzone.com/links/add.html?title=Haskell+While+Loop&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F09%2F15%2Fhaskell-while-loop%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/dzone.png" alt="Vote on DZone" title="Vote on DZone" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.facebook.com/sharer.php?t=Haskell+While+Loop&amp;u=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F09%2F15%2Fhaskell-while-loop%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/facebook.png" alt="Share on Facebook" title="Share on Facebook" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://delicious.com/save?title=Haskell+While+Loop&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F09%2F15%2Fhaskell-while-loop%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/delicious.png" alt="Bookmark this on Delicious" title="Bookmark this on Delicious" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dotnetkicks.com/kick/?title=Haskell+While+Loop&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F09%2F15%2Fhaskell-while-loop%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/dotnetkicks.png" alt="Kick It on DotNetKicks.com" title="Kick It on DotNetKicks.com" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://dotnetshoutout.com/Submit?title=Haskell+While+Loop&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F09%2F15%2Fhaskell-while-loop%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/dotnetshoutout.png" alt="Shout it" title="Shout it" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F09%2F15%2Fhaskell-while-loop%2F&amp;title=Haskell+While+Loop&amp;summary=&amp;source=" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/linkedin.png" alt="Share on LinkedIn" title="Share on LinkedIn" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.technorati.com/faves?add=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F09%2F15%2Fhaskell-while-loop%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/technorati.png" alt="Bookmark this on Technorati" title="Bookmark this on Technorati" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://twitter.com/home?status=Reading+http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F09%2F15%2Fhaskell-while-loop%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/twitter.png" alt="Post on Twitter" title="Post on Twitter" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.google.com/buzz/post?url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F09%2F15%2Fhaskell-while-loop%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/google_buzz.png" alt="Google Buzz (aka. Google Reader)" title="Google Buzz (aka. Google Reader)" /></a>&nbsp;&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://blog.willdonnelly.net/2009/09/15/haskell-while-loop/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>The Magic Dot</title>
		<link>http://blog.willdonnelly.net/2009/08/24/the-magic-dot/</link>
		<comments>http://blog.willdonnelly.net/2009/08/24/the-magic-dot/#comments</comments>
		<pubDate>Mon, 24 Aug 2009 16:45:02 +0000</pubDate>
		<dc:creator>Will Donnelly</dc:creator>
				<category><![CDATA[haskell]]></category>
		<category><![CDATA[fmap]]></category>
		<category><![CDATA[prelude]]></category>

		<guid isPermaLink="false">http://willdonnelly.wordpress.com/?p=279</guid>
		<description><![CDATA[So, reading about functors the other day, I noticed som [...]]]></description>
			<content:encoded><![CDATA[<p>So, reading about functors the other day, I noticed something interesting. Specifically, I noticed that in the case of functions,</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">fmap</div></div>
<p>is equivalent to the composition operation. I think</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">fmap</div></div>
<p>is possibly the coolest function in all of Haskell, so it annoys me when it requires six characters just to use it as an infix operator.</p>
<p>So I present what is, character-for-character, the coolest Haskell trick I have seen so far:</p>
<pre>import Prelude hiding ((.))
import Control.Monad.Instances
a . b = a `fmap` b
infixr 9 .</pre>
<p>And now, all sorts of fun little tricks are possible, like replacing</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&quot;map succ $ [0..9]&quot;</div></div>
<p>with</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&quot;succ . [0..9]&quot;</div></div>
<p>, and replacing</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&quot;getLine &amp;gt;&amp;gt;= return . (+1) . read&quot;</div></div>
<p>with</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&quot;(+1) . read . getLine&quot;</div></div>
<p><span style="background-color:#ffffff;">And of course, the same function composition magic still works like always.  Maybe it's just me, but something this simple, elegant, and fun to use just makes me happy inside.</span></p>
<p><span style="background-color:#ffffff;">But finally, I have to ask: is there any way of specifically declaring that a module *replaces* the standard Prelude (or even better, individual elements of it)? It would be really nice to just type </p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">import Prelude.MagicDot</div></div>
<p>and not have to also bother with adding </p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">import Prelude hiding ((.))</div></div>
<p></span></p>
<div class="lightsocial_container"><a class="lightsocial_a" href="http://digg.com/submit?url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F08%2F24%2Fthe-magic-dot%2F&amp;title=The+Magic+Dot" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/digg.png" alt="Digg This" title="Digg This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.reddit.com/submit?url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F08%2F24%2Fthe-magic-dot%2F&amp;title=The+Magic+Dot" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/reddit.png" alt="Reddit This" title="Reddit This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F08%2F24%2Fthe-magic-dot%2F&amp;title=The+Magic+Dot" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/stumbleupon.png" alt="Stumble Now!" title="Stumble Now!" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://buzz.yahoo.com/buzz?targetUrl=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F08%2F24%2Fthe-magic-dot%2F&amp;headline=The+Magic+Dot" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/yahoo_buzz.png" alt="Buzz This" title="Buzz This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dzone.com/links/add.html?title=The+Magic+Dot&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F08%2F24%2Fthe-magic-dot%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/dzone.png" alt="Vote on DZone" title="Vote on DZone" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.facebook.com/sharer.php?t=The+Magic+Dot&amp;u=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F08%2F24%2Fthe-magic-dot%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/facebook.png" alt="Share on Facebook" title="Share on Facebook" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://delicious.com/save?title=The+Magic+Dot&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F08%2F24%2Fthe-magic-dot%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/delicious.png" alt="Bookmark this on Delicious" title="Bookmark this on Delicious" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dotnetkicks.com/kick/?title=The+Magic+Dot&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F08%2F24%2Fthe-magic-dot%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/dotnetkicks.png" alt="Kick It on DotNetKicks.com" title="Kick It on DotNetKicks.com" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://dotnetshoutout.com/Submit?title=The+Magic+Dot&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F08%2F24%2Fthe-magic-dot%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/dotnetshoutout.png" alt="Shout it" title="Shout it" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F08%2F24%2Fthe-magic-dot%2F&amp;title=The+Magic+Dot&amp;summary=&amp;source=" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/linkedin.png" alt="Share on LinkedIn" title="Share on LinkedIn" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.technorati.com/faves?add=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F08%2F24%2Fthe-magic-dot%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/technorati.png" alt="Bookmark this on Technorati" title="Bookmark this on Technorati" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://twitter.com/home?status=Reading+http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F08%2F24%2Fthe-magic-dot%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/twitter.png" alt="Post on Twitter" title="Post on Twitter" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.google.com/buzz/post?url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F08%2F24%2Fthe-magic-dot%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/google_buzz.png" alt="Google Buzz (aka. Google Reader)" title="Google Buzz (aka. Google Reader)" /></a>&nbsp;&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://blog.willdonnelly.net/2009/08/24/the-magic-dot/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Haskell Exceptions</title>
		<link>http://blog.willdonnelly.net/2009/07/18/haskell-exceptions/</link>
		<comments>http://blog.willdonnelly.net/2009/07/18/haskell-exceptions/#comments</comments>
		<pubDate>Sat, 18 Jul 2009 23:36:31 +0000</pubDate>
		<dc:creator>Will Donnelly</dc:creator>
				<category><![CDATA[haskell]]></category>
		<category><![CDATA[error handling]]></category>

		<guid isPermaLink="false">http://willdonnelly.wordpress.com/?p=266</guid>
		<description><![CDATA[Haskell's absolute worst feature, in my opinion, is its [...]]]></description>
			<content:encoded><![CDATA[<p>Haskell's absolute worst feature, in my opinion, is its system of exceptions. I have yet to see a single use of exceptions that wouldn't be better served by the use of a "Maybe" or an "Either" type. Luckily, in a small nod to sanity, Haskell provides 'Control.Exception.Base.try', which returns an Either type, with the exception left, and the value right.</p>
<p>Once you have that, it becomes easy to implement some sane functionality for exception handling, such as my current favorite functions, <code class="codecolorer text default"><span class="text">defaultOnError</span></code> and <code class="codecolorer text default"><span class="text">errorToMaybe</span></code>:</p>
<div class="codecolorer-container haskell default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="haskell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">defaultOnError <span style="color: #339933; font-weight: bold;">::</span> a <span style="color: #339933; font-weight: bold;">-&gt;</span> <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#t:IO"><span style="color: #cccc00; font-weight: bold;">IO</span></a> a <span style="color: #339933; font-weight: bold;">-&gt;</span> <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#t:IO"><span style="color: #cccc00; font-weight: bold;">IO</span></a> a<br />
defaultOnError d a <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">do</span> tryValue <span style="color: #339933; font-weight: bold;">&lt;-</span> try a<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #06c; font-weight: bold;">case</span> tryValue <span style="color: #06c; font-weight: bold;">of</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Left &nbsp;<span style="color: #339933; font-weight: bold;">_</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:return"><span style="font-weight: bold;">return</span></a> d<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Right v <span style="color: #339933; font-weight: bold;">-&gt;</span> <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:return"><span style="font-weight: bold;">return</span></a> v<br />
errorToMaybe <span style="color: #339933; font-weight: bold;">::</span> <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#t:IO"><span style="color: #cccc00; font-weight: bold;">IO</span></a> a <span style="color: #339933; font-weight: bold;">-&gt;</span> <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#t:IO"><span style="color: #cccc00; font-weight: bold;">IO</span></a> <span style="color: green;">&#40;</span><a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#t:Maybe"><span style="color: #cccc00; font-weight: bold;">Maybe</span></a> a<span style="color: green;">&#41;</span><br />
errorToMaybe a <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">do</span> tryValue <span style="color: #339933; font-weight: bold;">&lt;-</span> try a<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #06c; font-weight: bold;">case</span> tryValue <span style="color: #06c; font-weight: bold;">of</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Left &nbsp;<span style="color: #339933; font-weight: bold;">_</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:return"><span style="font-weight: bold;">return</span></a> <span style="color: #339933; font-weight: bold;">$</span> Nothing<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Right v <span style="color: #339933; font-weight: bold;">-&gt;</span> <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:return"><span style="font-weight: bold;">return</span></a> <span style="color: #339933; font-weight: bold;">$</span> Just v</div></div>
<script type="text/javascript">
var flattr_wp_ver = '0.9.11';
var flattr_uid = '19057';
var flattr_url = 'http://blog.willdonnelly.net';
var flattr_lng = 'en_GB';
var flattr_cat = 'text';
var flattr_tag = 'blog,wordpress,rss,feed';
var flattr_btn = 'large';
var flattr_tle = 'It Seemed Like a Good Idea at the Time';
var flattr_dsc = 'Coding, Mostly';
</script>
<script src="http://api.flattr.com/button/load.js?v=0.2" type="text/javascript"></script><div class="lightsocial_container"><a class="lightsocial_a" href="http://digg.com/submit?url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F07%2F18%2Fhaskell-exceptions%2F&amp;title=Haskell+Exceptions" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/digg.png" alt="Digg This" title="Digg This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.reddit.com/submit?url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F07%2F18%2Fhaskell-exceptions%2F&amp;title=Haskell+Exceptions" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/reddit.png" alt="Reddit This" title="Reddit This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F07%2F18%2Fhaskell-exceptions%2F&amp;title=Haskell+Exceptions" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/stumbleupon.png" alt="Stumble Now!" title="Stumble Now!" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://buzz.yahoo.com/buzz?targetUrl=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F07%2F18%2Fhaskell-exceptions%2F&amp;headline=Haskell+Exceptions" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/yahoo_buzz.png" alt="Buzz This" title="Buzz This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dzone.com/links/add.html?title=Haskell+Exceptions&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F07%2F18%2Fhaskell-exceptions%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/dzone.png" alt="Vote on DZone" title="Vote on DZone" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.facebook.com/sharer.php?t=Haskell+Exceptions&amp;u=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F07%2F18%2Fhaskell-exceptions%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/facebook.png" alt="Share on Facebook" title="Share on Facebook" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://delicious.com/save?title=Haskell+Exceptions&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F07%2F18%2Fhaskell-exceptions%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/delicious.png" alt="Bookmark this on Delicious" title="Bookmark this on Delicious" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dotnetkicks.com/kick/?title=Haskell+Exceptions&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F07%2F18%2Fhaskell-exceptions%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/dotnetkicks.png" alt="Kick It on DotNetKicks.com" title="Kick It on DotNetKicks.com" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://dotnetshoutout.com/Submit?title=Haskell+Exceptions&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F07%2F18%2Fhaskell-exceptions%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/dotnetshoutout.png" alt="Shout it" title="Shout it" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F07%2F18%2Fhaskell-exceptions%2F&amp;title=Haskell+Exceptions&amp;summary=&amp;source=" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/linkedin.png" alt="Share on LinkedIn" title="Share on LinkedIn" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.technorati.com/faves?add=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F07%2F18%2Fhaskell-exceptions%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/technorati.png" alt="Bookmark this on Technorati" title="Bookmark this on Technorati" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://twitter.com/home?status=Reading+http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F07%2F18%2Fhaskell-exceptions%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/twitter.png" alt="Post on Twitter" title="Post on Twitter" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.google.com/buzz/post?url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F07%2F18%2Fhaskell-exceptions%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/google_buzz.png" alt="Google Buzz (aka. Google Reader)" title="Google Buzz (aka. Google Reader)" /></a>&nbsp;&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://blog.willdonnelly.net/2009/07/18/haskell-exceptions/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Useful Haskell List Function</title>
		<link>http://blog.willdonnelly.net/2009/07/12/useful-haskell-list-function/</link>
		<comments>http://blog.willdonnelly.net/2009/07/12/useful-haskell-list-function/#comments</comments>
		<pubDate>Sun, 12 Jul 2009 20:09:41 +0000</pubDate>
		<dc:creator>Will Donnelly</dc:creator>
				<category><![CDATA[haskell]]></category>

		<guid isPermaLink="false">http://willdonnelly.wordpress.com/?p=262</guid>
		<description><![CDATA[I keep finding myself with a long list of elements, whi [...]]]></description>
			<content:encoded><![CDATA[<p>I keep finding myself with a long list of elements, which I need to split into a list of lists of those elements. For example, I need to go from <code class="codecolorer text default"><span class="text">[0,1,2,3,4,5,6,7,8]</span></code> to <code class="codecolorer text default"><span class="text">[[0,1,2],[3,4,5],[6,7,8]]</span></code></p>
<p>So far, the best function I have found to do this is</p>
<div class="codecolorer-container haskell default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="haskell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">split <span style="color: #339933; font-weight: bold;">::</span> <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#t:Int"><span style="color: #cccc00; font-weight: bold;">Int</span></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> <span style="color: green;">&#91;</span><span style="color: green;">&#91;</span>a<span style="color: green;">&#93;</span><span style="color: green;">&#93;</span><br />
split n <span style="color: #339933; font-weight: bold;">=</span> unfoldr <span style="color: green;">&#40;</span>\r <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: #06c; font-weight: bold;">case</span> r <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> Nothing; x <span style="color: #339933; font-weight: bold;">-&gt;</span> Just <span style="color: #339933; font-weight: bold;">$</span> <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:splitAt"><span style="font-weight: bold;">splitAt</span></a> n x<span style="color: green;">&#41;</span></div></div>
<p>But that seems a little bit overcomplicated for such a simple function. Am I missing a better, more obvious solution?</p>
<div class="lightsocial_container"><a class="lightsocial_a" href="http://digg.com/submit?url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F07%2F12%2Fuseful-haskell-list-function%2F&amp;title=Useful+Haskell+List+Function" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/digg.png" alt="Digg This" title="Digg This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.reddit.com/submit?url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F07%2F12%2Fuseful-haskell-list-function%2F&amp;title=Useful+Haskell+List+Function" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/reddit.png" alt="Reddit This" title="Reddit This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F07%2F12%2Fuseful-haskell-list-function%2F&amp;title=Useful+Haskell+List+Function" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/stumbleupon.png" alt="Stumble Now!" title="Stumble Now!" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://buzz.yahoo.com/buzz?targetUrl=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F07%2F12%2Fuseful-haskell-list-function%2F&amp;headline=Useful+Haskell+List+Function" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/yahoo_buzz.png" alt="Buzz This" title="Buzz This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dzone.com/links/add.html?title=Useful+Haskell+List+Function&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F07%2F12%2Fuseful-haskell-list-function%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/dzone.png" alt="Vote on DZone" title="Vote on DZone" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.facebook.com/sharer.php?t=Useful+Haskell+List+Function&amp;u=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F07%2F12%2Fuseful-haskell-list-function%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/facebook.png" alt="Share on Facebook" title="Share on Facebook" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://delicious.com/save?title=Useful+Haskell+List+Function&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F07%2F12%2Fuseful-haskell-list-function%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/delicious.png" alt="Bookmark this on Delicious" title="Bookmark this on Delicious" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dotnetkicks.com/kick/?title=Useful+Haskell+List+Function&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F07%2F12%2Fuseful-haskell-list-function%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/dotnetkicks.png" alt="Kick It on DotNetKicks.com" title="Kick It on DotNetKicks.com" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://dotnetshoutout.com/Submit?title=Useful+Haskell+List+Function&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F07%2F12%2Fuseful-haskell-list-function%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/dotnetshoutout.png" alt="Shout it" title="Shout it" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F07%2F12%2Fuseful-haskell-list-function%2F&amp;title=Useful+Haskell+List+Function&amp;summary=&amp;source=" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/linkedin.png" alt="Share on LinkedIn" title="Share on LinkedIn" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.technorati.com/faves?add=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F07%2F12%2Fuseful-haskell-list-function%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/technorati.png" alt="Bookmark this on Technorati" title="Bookmark this on Technorati" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://twitter.com/home?status=Reading+http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F07%2F12%2Fuseful-haskell-list-function%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/twitter.png" alt="Post on Twitter" title="Post on Twitter" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.google.com/buzz/post?url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F07%2F12%2Fuseful-haskell-list-function%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/google_buzz.png" alt="Google Buzz (aka. Google Reader)" title="Google Buzz (aka. Google Reader)" /></a>&nbsp;&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://blog.willdonnelly.net/2009/07/12/useful-haskell-list-function/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Super-Makefile has levelled up! SuperMakefile became BashBuild!</title>
		<link>http://blog.willdonnelly.net/2009/05/08/super-makefile-has-levelled-up-supermakefile-became-bashbuild/</link>
		<comments>http://blog.willdonnelly.net/2009/05/08/super-makefile-has-levelled-up-supermakefile-became-bashbuild/#comments</comments>
		<pubDate>Sat, 09 May 2009 04:55:07 +0000</pubDate>
		<dc:creator>Will Donnelly</dc:creator>
				<category><![CDATA[coding]]></category>

		<guid isPermaLink="false">http://willdonnelly.wordpress.com/?p=242</guid>
		<description><![CDATA[I had just about reached the limits of what was possibl [...]]]></description>
			<content:encoded><![CDATA[<p>I had just about reached the limits of what was possible with just a makefile, but I still felt like adding more. So I rewrote the thing today as a shell script. Now, you simply call it as './configure', and it generates the Makefile for you. The script is still configured in much the same manner as the old Makefile, except now you don't have to specify a compiler.</p>
<p>More importantly, the rewrite has allowed a whole bunch of new tricks, including:</p>
<ul>
<li>Command-line specification of the install prefix</li>
<li>Now the commands are familiar to anyone who has ever done a "./configure &amp;&amp; make &amp;&amp; sudo make install" before</li>
<li>Out of source builds are now implemented</li>
<li>Autodetection of the C compiler</li>
</ul>
<p>And most importantly:</p>
<ul>
<li>Plenty of room to grow</li>
</ul>
<p>Unfortunately, the code took a major step backwards in attractiveness. Over the next few days I may tinker around with it in an attempt to make it not look quite so bad, and possibly move more logic out into the configure script.</p>
<p>Other major news of the day: I finally dumped bzr for git, just so <a href="http://github.com/willdonnelly">I could use GitHub</a>. The new project is named <a href="http://github.com/willdonnelly/bashbuild/tree/master">BashBuild</a>.</p>
<script type="text/javascript">
var flattr_wp_ver = '0.9.11';
var flattr_uid = '19057';
var flattr_url = 'http://blog.willdonnelly.net';
var flattr_lng = 'en_GB';
var flattr_cat = 'text';
var flattr_tag = 'blog,wordpress,rss,feed';
var flattr_btn = 'large';
var flattr_tle = 'It Seemed Like a Good Idea at the Time';
var flattr_dsc = 'Coding, Mostly';
</script>
<script src="http://api.flattr.com/button/load.js?v=0.2" type="text/javascript"></script><div class="lightsocial_container"><a class="lightsocial_a" href="http://digg.com/submit?url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F05%2F08%2Fsuper-makefile-has-levelled-up-supermakefile-became-bashbuild%2F&amp;title=Super-Makefile+has+levelled+up%21+SuperMakefile+became+BashBuild%21" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/digg.png" alt="Digg This" title="Digg This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.reddit.com/submit?url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F05%2F08%2Fsuper-makefile-has-levelled-up-supermakefile-became-bashbuild%2F&amp;title=Super-Makefile+has+levelled+up%21+SuperMakefile+became+BashBuild%21" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/reddit.png" alt="Reddit This" title="Reddit This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F05%2F08%2Fsuper-makefile-has-levelled-up-supermakefile-became-bashbuild%2F&amp;title=Super-Makefile+has+levelled+up%21+SuperMakefile+became+BashBuild%21" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/stumbleupon.png" alt="Stumble Now!" title="Stumble Now!" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://buzz.yahoo.com/buzz?targetUrl=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F05%2F08%2Fsuper-makefile-has-levelled-up-supermakefile-became-bashbuild%2F&amp;headline=Super-Makefile+has+levelled+up%21+SuperMakefile+became+BashBuild%21" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/yahoo_buzz.png" alt="Buzz This" title="Buzz This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dzone.com/links/add.html?title=Super-Makefile+has+levelled+up%21+SuperMakefile+became+BashBuild%21&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F05%2F08%2Fsuper-makefile-has-levelled-up-supermakefile-became-bashbuild%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/dzone.png" alt="Vote on DZone" title="Vote on DZone" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.facebook.com/sharer.php?t=Super-Makefile+has+levelled+up%21+SuperMakefile+became+BashBuild%21&amp;u=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F05%2F08%2Fsuper-makefile-has-levelled-up-supermakefile-became-bashbuild%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/facebook.png" alt="Share on Facebook" title="Share on Facebook" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://delicious.com/save?title=Super-Makefile+has+levelled+up%21+SuperMakefile+became+BashBuild%21&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F05%2F08%2Fsuper-makefile-has-levelled-up-supermakefile-became-bashbuild%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/delicious.png" alt="Bookmark this on Delicious" title="Bookmark this on Delicious" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dotnetkicks.com/kick/?title=Super-Makefile+has+levelled+up%21+SuperMakefile+became+BashBuild%21&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F05%2F08%2Fsuper-makefile-has-levelled-up-supermakefile-became-bashbuild%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/dotnetkicks.png" alt="Kick It on DotNetKicks.com" title="Kick It on DotNetKicks.com" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://dotnetshoutout.com/Submit?title=Super-Makefile+has+levelled+up%21+SuperMakefile+became+BashBuild%21&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F05%2F08%2Fsuper-makefile-has-levelled-up-supermakefile-became-bashbuild%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/dotnetshoutout.png" alt="Shout it" title="Shout it" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F05%2F08%2Fsuper-makefile-has-levelled-up-supermakefile-became-bashbuild%2F&amp;title=Super-Makefile+has+levelled+up%21+SuperMakefile+became+BashBuild%21&amp;summary=&amp;source=" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/linkedin.png" alt="Share on LinkedIn" title="Share on LinkedIn" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.technorati.com/faves?add=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F05%2F08%2Fsuper-makefile-has-levelled-up-supermakefile-became-bashbuild%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/technorati.png" alt="Bookmark this on Technorati" title="Bookmark this on Technorati" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://twitter.com/home?status=Reading+http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F05%2F08%2Fsuper-makefile-has-levelled-up-supermakefile-became-bashbuild%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/twitter.png" alt="Post on Twitter" title="Post on Twitter" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.google.com/buzz/post?url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F05%2F08%2Fsuper-makefile-has-levelled-up-supermakefile-became-bashbuild%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/google_buzz.png" alt="Google Buzz (aka. Google Reader)" title="Google Buzz (aka. Google Reader)" /></a>&nbsp;&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://blog.willdonnelly.net/2009/05/08/super-makefile-has-levelled-up-supermakefile-became-bashbuild/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Revenge of the Super-Makefile</title>
		<link>http://blog.willdonnelly.net/2009/05/05/revenge-of-the-super-makefile/</link>
		<comments>http://blog.willdonnelly.net/2009/05/05/revenge-of-the-super-makefile/#comments</comments>
		<pubDate>Wed, 06 May 2009 01:35:32 +0000</pubDate>
		<dc:creator>Will Donnelly</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[makefile]]></category>

		<guid isPermaLink="false">http://willdonnelly.wordpress.com/?p=240</guid>
		<description><![CDATA[So today I found some more things that the old Makefile [...]]]></description>
			<content:encoded><![CDATA[<p>So today I found some more things that the old Makefile was lacking. An "install" target, a ".PHONY" target to prevent breakage down the line, and the ability to recursively build subprojects. A few hours later, I have this:</p>
<div class="codecolorer-container make default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="make codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PROJECT<span style="color: #004400;">=</span>foo<br />
VERSION<span style="color: #004400;">=</span>0<span style="color: #004400;">.</span>0<span style="color: #004400;">.</span>1<br />
SOURCES<span style="color: #004400;">=</span>bar<span style="color: #004400;">.</span>c baz<span style="color: #004400;">.</span>c<br />
SUBPROJECTS<span style="color: #004400;">=</span>xyzzy fnord<br />
LIBRARY<span style="color: #004400;">=-</span>lm<br />
INCPATHS<span style="color: #004400;">=</span>xyzzy fnord<br />
LIBPATHS<span style="color: #004400;">=</span>fnord<br />
PREFIX<span style="color: #004400;">=/</span>usr<span style="color: #004400;">/</span>local<br />
LDFLAGS<span style="color: #004400;">=</span><br />
CFLAGS<span style="color: #004400;">=-</span>c <span style="color: #004400;">-</span>Wall <span style="color: #004400;">-</span>g<br />
CC<span style="color: #004400;">=</span>gcc<br />
<br />
<span style="color: #339900; font-style: italic;"># ------------ MAGIC BEGINS HERE -------------</span><br />
<br />
<span style="color: #339900; font-style: italic;"># We want subprojects to use these variables</span><br />
<span style="color: #666622; font-weight: bold;">export</span> CC<br />
<span style="color: #666622; font-weight: bold;">export</span> PREFIX<br />
<br />
<span style="color: #339900; font-style: italic;"># Automatic generation of some important lists</span><br />
OBJECTS<span style="color: #004400;">=$</span><span style="color: #004400;">&#40;</span>SOURCES<span style="color: #004400;">:.</span>c<span style="color: #004400;">=.</span>o<span style="color: #004400;">&#41;</span><br />
INCFLAGS<span style="color: #004400;">=$</span><span style="color: #004400;">&#40;</span><span style="color: #0000CC; font-weight: bold;">foreach</span> TMP<span style="color: #004400;">,$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">INCPATHS</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">,-</span>I<span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">TMP</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">&#41;</span><br />
LIBFLAGS<span style="color: #004400;">=$</span><span style="color: #004400;">&#40;</span><span style="color: #0000CC; font-weight: bold;">foreach</span> TMP<span style="color: #004400;">,$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">LIBPATHS</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">,-</span>L<span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">TMP</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">&#41;</span><br />
<br />
<span style="color: #339900; font-style: italic;"># Set up the output file names for the different output types</span><br />
<span style="color: #666622; font-weight: bold;">ifeq</span> <span style="color: #CC2200;">&quot;$(LIBRARY)&quot;</span> <span style="color: #CC2200;">&quot;shared&quot;</span><br />
&nbsp; &nbsp; BINARY<span style="color: #004400;">=</span>lib<span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">PROJECT</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">.</span>so<br />
<span style="color: #666622; font-weight: bold;">else</span> <span style="color: #666622; font-weight: bold;">ifeq</span> <span style="color: #CC2200;">&quot;$(LIBRARY)&quot;</span> <span style="color: #CC2200;">&quot;static&quot;</span><br />
&nbsp; &nbsp; BINARY<span style="color: #004400;">=</span>lib<span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">PROJECT</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">.</span>a<br />
<span style="color: #666622; font-weight: bold;">else</span><br />
&nbsp; &nbsp; BINARY<span style="color: #004400;">=$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">PROJECT</span><span style="color: #004400;">&#41;</span><br />
<span style="color: #666622; font-weight: bold;">endif</span><br />
<br />
all<span style="color: #004400;">:</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">SOURCES</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">SUBPROJECTS</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">BINARY</span><span style="color: #004400;">&#41;</span><br />
<br />
<span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">BINARY</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">:</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">OBJECTS</span><span style="color: #004400;">&#41;</span><br />
<span style="color: #666622; font-weight: bold;">ifdef</span> SOURCES<br />
&nbsp; &nbsp; <span style="color: #339900; font-style: italic;"># Assemble the object files into the right type of binary</span><br />
&nbsp; &nbsp; <span style="color: #666622; font-weight: bold;">ifeq</span> <span style="color: #CC2200;">&quot;$(LIBRARY)&quot;</span> <span style="color: #CC2200;">&quot;static&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; ar rcs <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">BINARY</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">OBJECTS</span><span style="color: #004400;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #666622; font-weight: bold;">else</span> <span style="color: #666622; font-weight: bold;">ifeq</span> <span style="color: #CC2200;">&quot;$(LIBRARY)&quot;</span> <span style="color: #CC2200;">&quot;shared&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">CC</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">-</span>shared <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">LIBFLAGS</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">OBJECTS</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">LDFLAGS</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">-</span>o <span style="color: #000088; font-weight: bold;">$@</span><br />
&nbsp; &nbsp; <span style="color: #666622; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">CC</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">LIBFLAGS</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">OBJECTS</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">LDFLAGS</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">-</span>o <span style="color: #000088; font-weight: bold;">$@</span><br />
&nbsp; &nbsp; <span style="color: #666622; font-weight: bold;">endif</span><br />
<span style="color: #666622; font-weight: bold;">endif</span><br />
<br />
<span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">SUBPROJECTS</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; make <span style="color: #004400;">-</span>e <span style="color: #004400;">-</span>C <span style="color: #000088; font-weight: bold;">$@</span><br />
<br />
<span style="color: #004400;">.</span>c<span style="color: #004400;">.</span>o<span style="color: #004400;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">CC</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">INCFLAGS</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">CFLAGS</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">-</span>fPIC <span style="color: #000088; font-weight: bold;">$&lt;</span> <span style="color: #004400;">-</span>o <span style="color: #000088; font-weight: bold;">$@</span><br />
<br />
install<span style="color: #004400;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004400;">@</span> for i in <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">SUBPROJECTS</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">;</span> do make <span style="color: #004400;">-</span>e <span style="color: #004400;">-</span>C <span style="color: #000088; font-weight: bold;">$$</span><span style="color: #004400;">&#123;</span>i<span style="color: #004400;">&#125;</span> install<span style="color: #004400;">;</span> done<br />
<span style="color: #666622; font-weight: bold;">ifdef</span> SOURCES<br />
&nbsp; &nbsp; <span style="color: #666622; font-weight: bold;">ifeq</span> <span style="color: #CC2200;">&quot;$(LIBRARY)&quot;</span> <span style="color: #CC2200;">&quot;static&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; install <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">BINARY</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">PREFIX</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">/</span>lib<br />
&nbsp; &nbsp; <span style="color: #666622; font-weight: bold;">else</span> <span style="color: #666622; font-weight: bold;">ifeq</span> <span style="color: #CC2200;">&quot;$(LIBRARY)&quot;</span> <span style="color: #CC2200;">&quot;shared&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; install <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">BINARY</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">PREFIX</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">/</span>lib<br />
&nbsp; &nbsp; <span style="color: #666622; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; install <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">BINARY</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">PREFIX</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">/</span>bin<br />
&nbsp; &nbsp; <span style="color: #666622; font-weight: bold;">endif</span><br />
<span style="color: #666622; font-weight: bold;">endif</span><br />
<br />
distclean<span style="color: #004400;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; rm <span style="color: #004400;">-</span>f <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">BINARY</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">OBJECTS</span><span style="color: #004400;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004400;">@</span> for i in <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">SUBPROJECTS</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">;</span> do make <span style="color: #004400;">-</span>C <span style="color: #000088; font-weight: bold;">$$</span><span style="color: #004400;">&#123;</span>i<span style="color: #004400;">&#125;</span> distclean<span style="color: #004400;">;</span> done<br />
<br />
clean<span style="color: #004400;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; rm <span style="color: #004400;">-</span>f <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">OBJECTS</span><span style="color: #004400;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004400;">@</span> for i in <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">SUBPROJECTS</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">;</span> do make <span style="color: #004400;">-</span>C <span style="color: #000088; font-weight: bold;">$$</span><span style="color: #004400;">&#123;</span>i<span style="color: #004400;">&#125;</span> clean<span style="color: #004400;">;</span> done<br />
<br />
<span style="color: #990000;">.PHONY</span><span style="color: #004400;">:</span> all clean distclean install <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">SUBPROJECTS</span><span style="color: #004400;">&#41;</span></div></div>
<p>It's longer, but not by too much, and now I can safely say it has everything I have ever needed in a fancy build system. It would be nice if I could get pretty colourized output, but this Makefile reliably builds, cleans, and installs the projects I have tested it on.</p>
<div class="lightsocial_container"><a class="lightsocial_a" href="http://digg.com/submit?url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F05%2F05%2Frevenge-of-the-super-makefile%2F&amp;title=Revenge+of+the+Super-Makefile" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/digg.png" alt="Digg This" title="Digg This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.reddit.com/submit?url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F05%2F05%2Frevenge-of-the-super-makefile%2F&amp;title=Revenge+of+the+Super-Makefile" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/reddit.png" alt="Reddit This" title="Reddit This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F05%2F05%2Frevenge-of-the-super-makefile%2F&amp;title=Revenge+of+the+Super-Makefile" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/stumbleupon.png" alt="Stumble Now!" title="Stumble Now!" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://buzz.yahoo.com/buzz?targetUrl=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F05%2F05%2Frevenge-of-the-super-makefile%2F&amp;headline=Revenge+of+the+Super-Makefile" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/yahoo_buzz.png" alt="Buzz This" title="Buzz This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dzone.com/links/add.html?title=Revenge+of+the+Super-Makefile&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F05%2F05%2Frevenge-of-the-super-makefile%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/dzone.png" alt="Vote on DZone" title="Vote on DZone" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.facebook.com/sharer.php?t=Revenge+of+the+Super-Makefile&amp;u=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F05%2F05%2Frevenge-of-the-super-makefile%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/facebook.png" alt="Share on Facebook" title="Share on Facebook" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://delicious.com/save?title=Revenge+of+the+Super-Makefile&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F05%2F05%2Frevenge-of-the-super-makefile%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/delicious.png" alt="Bookmark this on Delicious" title="Bookmark this on Delicious" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dotnetkicks.com/kick/?title=Revenge+of+the+Super-Makefile&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F05%2F05%2Frevenge-of-the-super-makefile%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/dotnetkicks.png" alt="Kick It on DotNetKicks.com" title="Kick It on DotNetKicks.com" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://dotnetshoutout.com/Submit?title=Revenge+of+the+Super-Makefile&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F05%2F05%2Frevenge-of-the-super-makefile%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/dotnetshoutout.png" alt="Shout it" title="Shout it" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F05%2F05%2Frevenge-of-the-super-makefile%2F&amp;title=Revenge+of+the+Super-Makefile&amp;summary=&amp;source=" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/linkedin.png" alt="Share on LinkedIn" title="Share on LinkedIn" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.technorati.com/faves?add=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F05%2F05%2Frevenge-of-the-super-makefile%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/technorati.png" alt="Bookmark this on Technorati" title="Bookmark this on Technorati" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://twitter.com/home?status=Reading+http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F05%2F05%2Frevenge-of-the-super-makefile%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/twitter.png" alt="Post on Twitter" title="Post on Twitter" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.google.com/buzz/post?url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F05%2F05%2Frevenge-of-the-super-makefile%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/google_buzz.png" alt="Google Buzz (aka. Google Reader)" title="Google Buzz (aka. Google Reader)" /></a>&nbsp;&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://blog.willdonnelly.net/2009/05/05/revenge-of-the-super-makefile/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Super-Makefile</title>
		<link>http://blog.willdonnelly.net/2009/05/04/the-super-makefile/</link>
		<comments>http://blog.willdonnelly.net/2009/05/04/the-super-makefile/#comments</comments>
		<pubDate>Tue, 05 May 2009 01:36:05 +0000</pubDate>
		<dc:creator>Will Donnelly</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[makefile]]></category>

		<guid isPermaLink="false">http://willdonnelly.wordpress.com/?p=233</guid>
		<description><![CDATA[After toying with build systems off and on for months,  [...]]]></description>
			<content:encoded><![CDATA[<p>After toying with build systems off and on for months, I concluded today that make is about as advanced as I ever need to get for my projects. In the past, I recall using <a title="Very generic makefile" href="http://mrbook.org/downloads/make/Makefile-4">this gem</a> of a Makefile.  But my needs in a build process have grown a little. First of all, I now prefer C to C++, so that had to be changed. Then I had to go about adding static and shared library abilities to it. Then I added "clean" and "distclean" build targets, and include and library search paths got introduced somewhere along the way.</p>
<p>After good half hour of modification, I had the following Makefile, posted here mainly so I can find it easily from any computer. By modifying the first six variables defined in the Makefile, it can be adapted to almost any C project of reasonable complexity. It has no support for cross-platform library identification, out-of-source builds, or debug and release build toggles. But on the other hand, I can never get those things to work right any way.</p>
<p>Toggling between static library, shared library, and executable build modes is performed by setting the LIBRARY variable to "static", "shared", or anything that isn't those two values.</p>
<div class="codecolorer-container make default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="make codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PROJECT<span style="color: #004400;">=</span>foo<br />
SOURCES<span style="color: #004400;">=</span>bar<span style="color: #004400;">.</span>c baz<span style="color: #004400;">.</span>c<br />
LIBRARY<span style="color: #004400;">=</span>nope<br />
INCPATHS<span style="color: #004400;">=../</span>some_other_project<span style="color: #004400;">/</span><br />
LIBPATHS<span style="color: #004400;">=../</span>yet_another_project<span style="color: #004400;">/</span><br />
LDFLAGS<span style="color: #004400;">=-</span>ldosomething<br />
CFLAGS<span style="color: #004400;">=-</span>c <span style="color: #004400;">-</span>Wall<br />
CC<span style="color: #004400;">=</span>gcc<br />
<br />
<span style="color: #339900; font-style: italic;"># ------------ MAGIC BEGINS HERE -------------</span><br />
<br />
<span style="color: #339900; font-style: italic;"># Automatic generation of some important lists</span><br />
OBJECTS<span style="color: #004400;">=$</span><span style="color: #004400;">&#40;</span>SOURCES<span style="color: #004400;">:.</span>c<span style="color: #004400;">=.</span>o<span style="color: #004400;">&#41;</span><br />
INCFLAGS<span style="color: #004400;">=$</span><span style="color: #004400;">&#40;</span><span style="color: #0000CC; font-weight: bold;">foreach</span> TMP<span style="color: #004400;">,$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">INCPATHS</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">,-</span>I<span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">TMP</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">&#41;</span><br />
LIBFLAGS<span style="color: #004400;">=$</span><span style="color: #004400;">&#40;</span><span style="color: #0000CC; font-weight: bold;">foreach</span> TMP<span style="color: #004400;">,$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">LIBPATHS</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">,-</span>L<span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">TMP</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">&#41;</span><br />
<br />
<span style="color: #339900; font-style: italic;"># Set up the output file names for the different output types</span><br />
<span style="color: #666622; font-weight: bold;">ifeq</span> <span style="color: #CC2200;">&quot;$(LIBRARY)&quot;</span> <span style="color: #CC2200;">&quot;shared&quot;</span><br />
&nbsp; &nbsp; BINARY<span style="color: #004400;">=</span>lib<span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">PROJECT</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">.</span>so<br />
&nbsp; &nbsp; LDFLAGS <span style="color: #004400;">+=</span> <span style="color: #004400;">-</span>shared<br />
<span style="color: #666622; font-weight: bold;">else</span> <span style="color: #666622; font-weight: bold;">ifeq</span> <span style="color: #CC2200;">&quot;$(LIBRARY)&quot;</span> <span style="color: #CC2200;">&quot;static&quot;</span><br />
&nbsp; &nbsp; BINARY<span style="color: #004400;">=</span>lib<span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">PROJECT</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">.</span>a<br />
<span style="color: #666622; font-weight: bold;">else</span><br />
&nbsp; &nbsp; BINARY<span style="color: #004400;">=$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">PROJECT</span><span style="color: #004400;">&#41;</span><br />
<span style="color: #666622; font-weight: bold;">endif</span><br />
<br />
all<span style="color: #004400;">:</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">SOURCES</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">BINARY</span><span style="color: #004400;">&#41;</span><br />
<br />
<span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">BINARY</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">:</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">OBJECTS</span><span style="color: #004400;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #339900; font-style: italic;"># Link the object files, or archive into a static library</span><br />
&nbsp; &nbsp; <span style="color: #666622; font-weight: bold;">ifeq</span> <span style="color: #CC2200;">&quot;$(LIBRARY)&quot;</span> <span style="color: #CC2200;">&quot;static&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; ar rcs <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">BINARY</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">OBJECTS</span><span style="color: #004400;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #666622; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">CC</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">LIBFLAGS</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">OBJECTS</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">LDFLAGS</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">-</span>o <span style="color: #000088; font-weight: bold;">$@</span><br />
&nbsp; &nbsp; <span style="color: #666622; font-weight: bold;">endif</span><br />
<br />
<span style="color: #004400;">.</span>c<span style="color: #004400;">.</span>o<span style="color: #004400;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">CC</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">INCFLAGS</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">CFLAGS</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">-</span>fPIC <span style="color: #000088; font-weight: bold;">$&lt;</span> <span style="color: #004400;">-</span>o <span style="color: #000088; font-weight: bold;">$@</span><br />
<br />
distclean<span style="color: #004400;">:</span> clean<br />
&nbsp; &nbsp; &nbsp; &nbsp; rm <span style="color: #004400;">-</span>f <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">BINARY</span><span style="color: #004400;">&#41;</span><br />
<br />
clean<span style="color: #004400;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; rm <span style="color: #004400;">-</span>f <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">OBJECTS</span><span style="color: #004400;">&#41;</span></div></div>
<script type="text/javascript">
var flattr_wp_ver = '0.9.11';
var flattr_uid = '19057';
var flattr_url = 'http://blog.willdonnelly.net';
var flattr_lng = 'en_GB';
var flattr_cat = 'text';
var flattr_tag = 'blog,wordpress,rss,feed';
var flattr_btn = 'large';
var flattr_tle = 'It Seemed Like a Good Idea at the Time';
var flattr_dsc = 'Coding, Mostly';
</script>
<script src="http://api.flattr.com/button/load.js?v=0.2" type="text/javascript"></script><div class="lightsocial_container"><a class="lightsocial_a" href="http://digg.com/submit?url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F05%2F04%2Fthe-super-makefile%2F&amp;title=The+Super-Makefile" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/digg.png" alt="Digg This" title="Digg This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.reddit.com/submit?url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F05%2F04%2Fthe-super-makefile%2F&amp;title=The+Super-Makefile" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/reddit.png" alt="Reddit This" title="Reddit This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F05%2F04%2Fthe-super-makefile%2F&amp;title=The+Super-Makefile" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/stumbleupon.png" alt="Stumble Now!" title="Stumble Now!" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://buzz.yahoo.com/buzz?targetUrl=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F05%2F04%2Fthe-super-makefile%2F&amp;headline=The+Super-Makefile" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/yahoo_buzz.png" alt="Buzz This" title="Buzz This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dzone.com/links/add.html?title=The+Super-Makefile&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F05%2F04%2Fthe-super-makefile%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/dzone.png" alt="Vote on DZone" title="Vote on DZone" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.facebook.com/sharer.php?t=The+Super-Makefile&amp;u=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F05%2F04%2Fthe-super-makefile%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/facebook.png" alt="Share on Facebook" title="Share on Facebook" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://delicious.com/save?title=The+Super-Makefile&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F05%2F04%2Fthe-super-makefile%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/delicious.png" alt="Bookmark this on Delicious" title="Bookmark this on Delicious" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dotnetkicks.com/kick/?title=The+Super-Makefile&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F05%2F04%2Fthe-super-makefile%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/dotnetkicks.png" alt="Kick It on DotNetKicks.com" title="Kick It on DotNetKicks.com" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://dotnetshoutout.com/Submit?title=The+Super-Makefile&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F05%2F04%2Fthe-super-makefile%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/dotnetshoutout.png" alt="Shout it" title="Shout it" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F05%2F04%2Fthe-super-makefile%2F&amp;title=The+Super-Makefile&amp;summary=&amp;source=" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/linkedin.png" alt="Share on LinkedIn" title="Share on LinkedIn" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.technorati.com/faves?add=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F05%2F04%2Fthe-super-makefile%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/technorati.png" alt="Bookmark this on Technorati" title="Bookmark this on Technorati" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://twitter.com/home?status=Reading+http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F05%2F04%2Fthe-super-makefile%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/twitter.png" alt="Post on Twitter" title="Post on Twitter" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.google.com/buzz/post?url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F05%2F04%2Fthe-super-makefile%2F" ><img class="lightsocial_img" src="http://blog.willdonnelly.net/wp-content/plugins/light-social/google_buzz.png" alt="Google Buzz (aka. Google Reader)" title="Google Buzz (aka. Google Reader)" /></a>&nbsp;&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://blog.willdonnelly.net/2009/05/04/the-super-makefile/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
