<?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</title>
	<atom:link href="http://blog.willdonnelly.net/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>Announcing the UCL Portability Libraries</title>
		<link>http://blog.willdonnelly.net/2010/08/20/announcing-the-ucl-portability-libraries/</link>
		<comments>http://blog.willdonnelly.net/2010/08/20/announcing-the-ucl-portability-libraries/#comments</comments>
		<pubDate>Fri, 20 Aug 2010 15:33:00 +0000</pubDate>
		<dc:creator>Will Donnelly</dc:creator>
				<category><![CDATA[scheme]]></category>
		<category><![CDATA[ucl]]></category>

		<guid isPermaLink="false">http://blog.willdonnelly.net/?p=400</guid>
		<description><![CDATA[I spent the last year learning Haskell, and it is a ver [...]]]></description>
			<content:encoded><![CDATA[<p>I spent the last year learning Haskell, and it is a very cool language. That said, I get the feeling that it also gains a gigantic competitive advantage from <a href="http://hackage.haskell.org/trac/hackage/wiki/CabalInstall">cabal-install</a> and <a href="http://hackage.haskell.org/packages/hackage.html">HackageDB</a>. Package repositories and install tools for languages are <a href="http://www.cpan.org/">not</a><a href="http://pypi.python.org/pypi"> a</a> <a href="http://rubygems.org/">new</a> <a href="http://snow.iro.umontreal.ca/">thing</a>, but it was Hackage that made me realize how effectively a common package infrastructure can help to raise the popularity of a language.</p>
<p>And here's the thing: to a sufficiently fuzzy approximation, all the R6RS Schemes out there are interchangeable. They all offer a foreign function interface with roughly the same capabilities, they all offer the ability to launch and control subprocesses, and just about anything else can be built up from there. All of the cool things that can be built from these primitives, there is no fundamental reason they can't be portable.</p>
<p>So in April I started working on a set of portability packages, followed by an install tool, followed by a web-based package upload and browsing interface. And now it's all sufficiently done that I feel like I should release it.</p>
<p><a href="http://ucl.willdonnelly.net/">So here you go</a>.</p>
<h2>Caveats</h2>
<p>It supports <a href="http://ikarus-scheme.org/">Ikarus</a>, <a href="http://www.larcenists.org/">Larceny</a>, <a href="http://mosh.monaos.org/">Mosh</a>, <a href="http://racket-lang.org/">Racket</a>, and <a href="http://code.google.com/p/ypsilon/">Ypsilon</a>, at least on my machine.</p>
<p>The install tool could certainly use more features, like a package upgrade ability, code precompilation for the various Schemes, and complex version constraints on packages. The web interface is horrible code, and I'm just happy it seems to work as well as it does.</p>
<p>But what I am proud of are the simple but extensible package format, with myriad available extension points for new features, the simple repository format which allows anyone to start serving up packages if they don't like my offering, and the libraries which allow FFI and process manipulation to operate identically across Schemes.</p>
<h2>Similar Projects</h2>
<p>This code doesn't exist in a vacuum, and there are other projects whose scope overlaps with mine.</p>
<p>The most noticeable, to me, is Marco Maggi's <a href="http://github.com/marcomaggi/nausicaa">Nausicaa</a>, a gargantuan library distribution for R6RS Schemes. I regret to say that I have no experience using it, but the sheer number of libraries is impressive. I would like nothing more than to see some of those libraries available through UCL Install at some point.</p>
<p>The only other R6RS package manager that I have heard of is <a href="http://rotty.yi.org/software/dorodango/">Dorodango</a>. It does not seem to have been officially released yet, and if I understand the documentation correctly, it only supports Ikarus and Ypsilon at this time. It does have an upgrade command, unlike UCL Install at this point.  I envy the awesome choice of name, and I look forward to seeing what the author does with this one in the future.</p>
<p>Finally we come to <a href="http://snow.iro.umontreal.ca/">Snowfort</a>, an older attempt at a Scheme packaging system. I do not believe it is R6RS compatible, as it defines its own module system, and it appears to have no FFI or other portability layers, so I believe packages are limited to pure Scheme code. I would like to look at either manually or automatically porting some of these packages at some point, if the authors are amenable.</p>
<div class="lightsocial_container"><a class="lightsocial_a" href="http://digg.com/submit?url=http%3A%2F%2Fblog.willdonnelly.net%2F2010%2F08%2F20%2Fannouncing-the-ucl-portability-libraries%2F&amp;title=Announcing+the+UCL+Portability+Libraries" ><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%2F2010%2F08%2F20%2Fannouncing-the-ucl-portability-libraries%2F&amp;title=Announcing+the+UCL+Portability+Libraries" ><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%2F2010%2F08%2F20%2Fannouncing-the-ucl-portability-libraries%2F&amp;title=Announcing+the+UCL+Portability+Libraries" ><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%2F2010%2F08%2F20%2Fannouncing-the-ucl-portability-libraries%2F&amp;headline=Announcing+the+UCL+Portability+Libraries" ><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=Announcing+the+UCL+Portability+Libraries&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2010%2F08%2F20%2Fannouncing-the-ucl-portability-libraries%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=Announcing+the+UCL+Portability+Libraries&amp;u=http%3A%2F%2Fblog.willdonnelly.net%2F2010%2F08%2F20%2Fannouncing-the-ucl-portability-libraries%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=Announcing+the+UCL+Portability+Libraries&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2010%2F08%2F20%2Fannouncing-the-ucl-portability-libraries%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=Announcing+the+UCL+Portability+Libraries&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2010%2F08%2F20%2Fannouncing-the-ucl-portability-libraries%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=Announcing+the+UCL+Portability+Libraries&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2010%2F08%2F20%2Fannouncing-the-ucl-portability-libraries%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%2F2010%2F08%2F20%2Fannouncing-the-ucl-portability-libraries%2F&amp;title=Announcing+the+UCL+Portability+Libraries&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%2F2010%2F08%2F20%2Fannouncing-the-ucl-portability-libraries%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%2F2010%2F08%2F20%2Fannouncing-the-ucl-portability-libraries%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%2F2010%2F08%2F20%2Fannouncing-the-ucl-portability-libraries%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/2010/08/20/announcing-the-ucl-portability-libraries/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>My Experience With STM32 Microcontrollers</title>
		<link>http://blog.willdonnelly.net/2010/04/11/my-experience-with-stm32-microcontrollers/</link>
		<comments>http://blog.willdonnelly.net/2010/04/11/my-experience-with-stm32-microcontrollers/#comments</comments>
		<pubDate>Sun, 11 Apr 2010 20:09:50 +0000</pubDate>
		<dc:creator>Will Donnelly</dc:creator>
				<category><![CDATA[electronics]]></category>
		<category><![CDATA[stm32]]></category>
		<category><![CDATA[dancefloor]]></category>

		<guid isPermaLink="false">http://blog.willdonnelly.net/?p=333</guid>
		<description><![CDATA[For some reason, I never talk much about my embedded de [...]]]></description>
			<content:encoded><![CDATA[<p>For some reason, I never talk much about my embedded development projects, which is odd considering the large amount of time that I spend on them. I started learning embedded development stuff back in my sophomore year of high school with the AVR line of microcontrollers.</p>
<div id="attachment_350" class="wp-caption alignleft" style="width: 160px"><a href="http://blog.willdonnelly.net/wp-content/uploads/bt-remote.jpg"><img class="size-thumbnail wp-image-350" title="Bluetooth Remote" src="http://blog.willdonnelly.net/wp-content/uploads/bt-remote-150x150.jpg" alt="My Prototype Remote Controller" width="150" height="150" /></a><p class="wp-caption-text">My Prototype Remote Controller</p></div>
<p>In my junior-senior year (it's a long story) I designed and built an embedded device to control NXT robots for the FTC robotics competition. I still have the original breadboarded prototype lying around.</p>
<p>But this post isn't about that, I was just providing some background information.</p>
<p>This year, <a href="http://ieee.wustl.edu/">IEEE@WashU</a> has decided to build a light-up dancefloor, similar to the <a title="The Old Dancefloor Build at Wash U" href="http://photos1.blogger.com/x/blogger/6304/1572/1600/282547/IMG_2749.jpg">old one</a>, but split into a set of modular 2-by-2-foot tiles for easier maintainability, upgradeability, and not-exploding-people-ability. Also it will have pressure sensing.</p>
<p>We were originally planning to run the floor with an ATMega at the center coordinating everything. Unfortunately, our first try at the inter-module communications was prone to noise issues. After much deliberation, we chose a scheme using ordinary UART signalling carried over LVDS between modules, with direct connections between neighboring modules. Unfortunately, that meant we needed a chip with 4 high-speed UARTs.</p>
<p>We ended up settling on the STM32 line of ARM chips, specifically the <a href="http://www.st.com/mcu/devicedocs-STM32F105R8-110.html">STM32F105</a>. It has 5 UARTs, of which all are capable of 2.25 Mbaud. Also it has on-board ADC functionality, and runs nearly 4x as fast as an AVR at top speed. So it's a pretty nice chip overall.</p>
<p>The first big problem was packaging. Most AVR chips come in a DIP package, which is nice and friendly for hand-soldering. The STM32F105, on the other hand, comes in a QFP-64 package, which is quite a bit less friendly. For prototyping, I soldered one to a <a href="http://www.proto-advantage.com/store/product_info.php?products_id=2200113">breakout board</a> by hand. It worked, sporadically, for about half a week, but I'm pretty sure my poor soldering is to blame for the failure, either due to bad electrical connections or thermal damage.</p>
<p>But from what I was able to infer about the operation of a non-damaged chip, the STM32 line should be pretty fun to work with.</p>
<ul>
<li>Like the AVR, it has extremely minimal requirements for external components. I ran it with power, JTAG, two blinky LEDs, and nothing else connected.</li>
<li>The STM32F10x Standard Peripheral Library contains a lot of useful functionality already implemented, although the function naming conventions are pretty ugly.</li>
<li>On-chip debugging is always worth it. AVR chips can do this too, but I never really bothered using it. Now that I've tried it on the STM32, I don't think I could bear blinky-LED debugging any more.</li>
<li>Lots of fun features:
<ul>
<li>4x higher clock speed than AVR.</li>
<li>Two 16-channel ADCs</li>
<li>Two 12-bit DACs</li>
<li>Unique 96-bit device signature</li>
</ul>
</li>
</ul>
<p>Aside from the soldering issue, I believe that the STM32 line of microcontrollers is exceptionally hobbyist friendly, and should be pretty fun to work with once I get some non-damaged chips hooked up.</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%2F2010%2F04%2F11%2Fmy-experience-with-stm32-microcontrollers%2F&amp;title=My+Experience+With+STM32+Microcontrollers" ><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%2F2010%2F04%2F11%2Fmy-experience-with-stm32-microcontrollers%2F&amp;title=My+Experience+With+STM32+Microcontrollers" ><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%2F2010%2F04%2F11%2Fmy-experience-with-stm32-microcontrollers%2F&amp;title=My+Experience+With+STM32+Microcontrollers" ><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%2F2010%2F04%2F11%2Fmy-experience-with-stm32-microcontrollers%2F&amp;headline=My+Experience+With+STM32+Microcontrollers" ><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=My+Experience+With+STM32+Microcontrollers&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2010%2F04%2F11%2Fmy-experience-with-stm32-microcontrollers%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=My+Experience+With+STM32+Microcontrollers&amp;u=http%3A%2F%2Fblog.willdonnelly.net%2F2010%2F04%2F11%2Fmy-experience-with-stm32-microcontrollers%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=My+Experience+With+STM32+Microcontrollers&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2010%2F04%2F11%2Fmy-experience-with-stm32-microcontrollers%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=My+Experience+With+STM32+Microcontrollers&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2010%2F04%2F11%2Fmy-experience-with-stm32-microcontrollers%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=My+Experience+With+STM32+Microcontrollers&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2010%2F04%2F11%2Fmy-experience-with-stm32-microcontrollers%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%2F2010%2F04%2F11%2Fmy-experience-with-stm32-microcontrollers%2F&amp;title=My+Experience+With+STM32+Microcontrollers&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%2F2010%2F04%2F11%2Fmy-experience-with-stm32-microcontrollers%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%2F2010%2F04%2F11%2Fmy-experience-with-stm32-microcontrollers%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%2F2010%2F04%2F11%2Fmy-experience-with-stm32-microcontrollers%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/2010/04/11/my-experience-with-stm32-microcontrollers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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>Useful Shell Trick</title>
		<link>http://blog.willdonnelly.net/2009/08/06/useful-shell-trick/</link>
		<comments>http://blog.willdonnelly.net/2009/08/06/useful-shell-trick/#comments</comments>
		<pubDate>Fri, 07 Aug 2009 03:40:41 +0000</pubDate>
		<dc:creator>Will Donnelly</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://willdonnelly.wordpress.com/?p=272</guid>
		<description><![CDATA[Sometimes, when doing a bunch of data munging in the sh [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes, when doing a bunch of data munging in the shell, I want to pass the contents of a file through a shell pipeline, and then directly out into the file again. Unfortunately, doing this the naive way will obliterate the file's contents.</p>
<p>So a while back, I saw a neat little utility called "sponge" which simply buffered data until it ended, and then output it. While useful, this wasn't a standard Unix tool, so I couldn't very well rely on having it available.</p>
<p>Well today, after literally <strong>minutes</strong> of searching, I have found a command that seems to work just as well:</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">tail -n +0</div></div>
<p>It outputs all lines in the input, beginning with line zero. Due, I suppose, to the way tail is implemented, it buffers all input before outputting anything.</p>
<p>Not exactly groundbreaking or anything, but a useful little trick to know when playing around in the shell.</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%2F08%2F06%2Fuseful-shell-trick%2F&amp;title=Useful+Shell+Trick" ><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%2F06%2Fuseful-shell-trick%2F&amp;title=Useful+Shell+Trick" ><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%2F06%2Fuseful-shell-trick%2F&amp;title=Useful+Shell+Trick" ><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%2F06%2Fuseful-shell-trick%2F&amp;headline=Useful+Shell+Trick" ><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+Shell+Trick&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F08%2F06%2Fuseful-shell-trick%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+Shell+Trick&amp;u=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F08%2F06%2Fuseful-shell-trick%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+Shell+Trick&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F08%2F06%2Fuseful-shell-trick%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+Shell+Trick&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F08%2F06%2Fuseful-shell-trick%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+Shell+Trick&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F08%2F06%2Fuseful-shell-trick%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%2F06%2Fuseful-shell-trick%2F&amp;title=Useful+Shell+Trick&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%2F06%2Fuseful-shell-trick%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%2F06%2Fuseful-shell-trick%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%2F06%2Fuseful-shell-trick%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/06/useful-shell-trick/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Git Short URLs</title>
		<link>http://blog.willdonnelly.net/2009/07/20/git-short-urls/</link>
		<comments>http://blog.willdonnelly.net/2009/07/20/git-short-urls/#comments</comments>
		<pubDate>Mon, 20 Jul 2009 19:27:48 +0000</pubDate>
		<dc:creator>Will Donnelly</dc:creator>
				<category><![CDATA[Note To Self]]></category>

		<guid isPermaLink="false">http://willdonnelly.wordpress.com/?p=268</guid>
		<description><![CDATA[I knew for a fact this feature existed, but even so it  [...]]]></description>
			<content:encoded><![CDATA[<p>I knew for a fact this feature existed, but even so it took me a half hour to track down the syntax for it. To prevent myself ever needing to do that again, I'm putting it here.</p>
<p>To create a nice, short URL abbreviation for git, such as <code class="codecolorer text default"><span class="text">myserver:&lt;project&gt;.git</span></code>, put the following in <code class="codecolorer text default"><span class="text">~/.gitconfig</span></code></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">[url &quot;ssh://MY-SERVER/~/&quot;]<br />
&nbsp; &nbsp; insteadOf = myserver:</div></div>
<p>That's all there is to it.</p>
<div class="lightsocial_container"><a class="lightsocial_a" href="http://digg.com/submit?url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F07%2F20%2Fgit-short-urls%2F&amp;title=Git+Short+URLs" ><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%2F20%2Fgit-short-urls%2F&amp;title=Git+Short+URLs" ><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%2F20%2Fgit-short-urls%2F&amp;title=Git+Short+URLs" ><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%2F20%2Fgit-short-urls%2F&amp;headline=Git+Short+URLs" ><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=Git+Short+URLs&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F07%2F20%2Fgit-short-urls%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=Git+Short+URLs&amp;u=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F07%2F20%2Fgit-short-urls%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=Git+Short+URLs&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F07%2F20%2Fgit-short-urls%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=Git+Short+URLs&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F07%2F20%2Fgit-short-urls%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=Git+Short+URLs&amp;url=http%3A%2F%2Fblog.willdonnelly.net%2F2009%2F07%2F20%2Fgit-short-urls%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%2F20%2Fgit-short-urls%2F&amp;title=Git+Short+URLs&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%2F20%2Fgit-short-urls%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%2F20%2Fgit-short-urls%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%2F20%2Fgit-short-urls%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/20/git-short-urls/feed/</wfw:commentRss>
		<slash:comments>0</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>
	</channel>
</rss>
