<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Martijn's Journal</title>
	
	<link>http://martijn.van.steenbergen.nl/journal</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Sat, 27 Feb 2010 11:23:32 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/MedeaMelana" /><feedburner:info uri="medeamelana" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Colors in GHCi</title>
		<link>http://feedproxy.google.com/~r/MedeaMelana/~3/S-2S1j2QNKY/</link>
		<comments>http://martijn.van.steenbergen.nl/journal/2010/02/27/colors-in-ghci/#comments</comments>
		<pubDate>Sat, 27 Feb 2010 11:10:47 +0000</pubDate>
		<dc:creator>Martijn</dc:creator>
				<category><![CDATA[Haskell]]></category>

		<guid isPermaLink="false">http://martijn.van.steenbergen.nl/journal/?p=467</guid>
		<description><![CDATA[Whenever you load a Haskell file into GHCi, it will either tell you your modules loaded fine, or that there were some errors. Sebas came with the awesome idea of coloring these messages green and red, respectively. Here is how to do this:
Create a script that looks like this:

#!/usr/bin/env bash

GREEN=`echo -e '\033[92m'`
RED=`echo -e '\033[91m'`
RESET=`echo -e [...]]]></description>
			<content:encoded><![CDATA[<p>Whenever you load a Haskell file into GHCi, it will either tell you your modules loaded fine, or that there were some errors. <a href="http://twitter.com/sfvisser">Sebas</a> came with the awesome idea of coloring these messages green and red, respectively. Here is how to do this:</p>
<p>Create a script that looks like this:</p>
<pre style="overflow: auto; margin-right: 120px">
#!/usr/bin/env bash

GREEN=`echo -e '\033[92m'`
RED=`echo -e '\033[91m'`
RESET=`echo -e '\033[0m'`

/usr/bin/ghci "${@}" |\
  sed "s/^Failed, modules loaded:/${RED}&#038;${RESET}/g;s/^Ok, modules loaded:/${GREEN}&#038;${RESET}/g"
</pre>
<p>If your <code>ghci</code> is not located in <code>/usr/bin</code>, change the path in the script accordingly. If you want, you can name your script <code>ghci</code> so that it takes over the original one. Just make sure its location appears in your <code>PATH</code> variable before the location of the true <code>ghci</code>.</p>
<p>If all goes well, you should now see colors whenever you load your modules:</p>
<pre style="background-color: #333; color: #a3bd84;">
% ghci Sirenial.Merge
...
<span style="color:#fd3a1e">Failed, modules loaded:</span> Sirenial.Query.
</pre>
<p>And then when the bug has been fixed:</p>
<pre style="background-color: #333; color: #a3bd84;">
% ghci Sirenial.Merge
...
<span style="color:#2fe424">Ok, modules loaded:</span> Sirenial.Merge, Sirenial.Query.
</pre>
<p>This has only been tested on Terminal.app in Snow Leopard. If it doesn&#8217;t work for your system, please leave a comment, with—if possible—a fix.</p>
<p>There is a small issue: sometimes <code>sed</code> delays the colored parts a bit, causing your prompt to be printed <em>before</em> the success or error message. Again, if you know a fix, please comment.</p>
<img src="http://feeds.feedburner.com/~r/MedeaMelana/~4/S-2S1j2QNKY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://martijn.van.steenbergen.nl/journal/2010/02/27/colors-in-ghci/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://martijn.van.steenbergen.nl/journal/2010/02/27/colors-in-ghci/</feedburner:origLink></item>
		<item>
		<title>Sneeuw at Warande</title>
		<link>http://feedproxy.google.com/~r/MedeaMelana/~3/hBRqHg3yNP8/</link>
		<comments>http://martijn.van.steenbergen.nl/journal/2009/12/21/sneeuw-at-warande/#comments</comments>
		<pubDate>Sun, 20 Dec 2009 23:07:47 +0000</pubDate>
		<dc:creator>Martijn</dc:creator>
				<category><![CDATA[Life]]></category>

		<guid isPermaLink="false">http://martijn.van.steenbergen.nl/journal/?p=458</guid>
		<description><![CDATA[
With the whole of the Netherlands covered in snow, the traffic is completely jammed. But that didn&#8217;t bother my flatmates and me, because we stayed home all day. In the afternoon we rolled the biggest snowball in the street; at the end it reached a meter in diameter and it took three of us to [...]]]></description>
			<content:encoded><![CDATA[<img class="dbg_single" src="http://martijn.van.steenbergen.nl/galleries/singles/DSC_0309.jpg" alt="DSC_0309.jpg" />
<p>With the whole of the Netherlands covered in snow, the traffic is completely jammed. But that didn&#8217;t bother my flatmates and me, because we stayed home all day. In the afternoon we rolled the biggest snowball in the street; at the end it reached a meter in diameter and it took three of us to push it around. We guessed it weighed approximately 250 kg at that point.</p>
<p>While <a href="http://www.ah.nl/recepten/recept?id=8478">dinner</a> was cooking I went outside again to take some pictures.</p>
<table cellspacing="0" cellpadding="0" class="dbg_gallery">
<tr>
<td>
<div class="dbg_picture_outer"><div class="dbg_picture_inner"><a href="http://martijn.van.steenbergen.nl/galleries/sneeuw-warande/DSC_0296.jpg" rel="lightbox[sneeuw-warande]" title="Our giant snowball. At the end it took 3 people to push it around.">
<img src="http://martijn.van.steenbergen.nl/thumbnails/sneeuw-warande/DSC_0296.jpg" alt="http://martijn.van.steenbergen.nl/thumbnails/sneeuw-warande/DSC_0296.jpg"/></a></div></div>
<div class="dbg_caption">Our giant snowball. At the end it took 3 people to push it around.</div>
</td>
<td>
<div class="dbg_picture_outer"><div class="dbg_picture_inner"><a href="http://martijn.van.steenbergen.nl/galleries/sneeuw-warande/DSC_0297.jpg" rel="lightbox[sneeuw-warande]" title="">
<img src="http://martijn.van.steenbergen.nl/thumbnails/sneeuw-warande/DSC_0297.jpg" alt="http://martijn.van.steenbergen.nl/thumbnails/sneeuw-warande/DSC_0297.jpg"/></a></div></div>
<div class="dbg_caption"></div>
</td>
<td>
<div class="dbg_picture_outer"><div class="dbg_picture_inner"><a href="http://martijn.van.steenbergen.nl/galleries/sneeuw-warande/DSC_0301.jpg" rel="lightbox[sneeuw-warande]" title="">
<img src="http://martijn.van.steenbergen.nl/thumbnails/sneeuw-warande/DSC_0301.jpg" alt="http://martijn.van.steenbergen.nl/thumbnails/sneeuw-warande/DSC_0301.jpg"/></a></div></div>
<div class="dbg_caption"></div>
</td>
<td>
<div class="dbg_picture_outer"><div class="dbg_picture_inner"><a href="http://martijn.van.steenbergen.nl/galleries/sneeuw-warande/DSC_0305.jpg" rel="lightbox[sneeuw-warande]" title="">
<img src="http://martijn.van.steenbergen.nl/thumbnails/sneeuw-warande/DSC_0305.jpg" alt="http://martijn.van.steenbergen.nl/thumbnails/sneeuw-warande/DSC_0305.jpg"/></a></div></div>
<div class="dbg_caption"></div>
</td>
</tr>
<tr>
<td>
<div class="dbg_picture_outer"><div class="dbg_picture_inner"><a href="http://martijn.van.steenbergen.nl/galleries/sneeuw-warande/DSC_0309.jpg" rel="lightbox[sneeuw-warande]" title="In the background is the orange-lit road.">
<img src="http://martijn.van.steenbergen.nl/thumbnails/sneeuw-warande/DSC_0309.jpg" alt="http://martijn.van.steenbergen.nl/thumbnails/sneeuw-warande/DSC_0309.jpg"/></a></div></div>
<div class="dbg_caption">In the background is the orange-lit road.</div>
</td>
<td>
<div class="dbg_picture_outer"><div class="dbg_picture_inner"><a href="http://martijn.van.steenbergen.nl/galleries/sneeuw-warande/DSC_0313.jpg" rel="lightbox[sneeuw-warande]" title="">
<img src="http://martijn.van.steenbergen.nl/thumbnails/sneeuw-warande/DSC_0313.jpg" alt="http://martijn.van.steenbergen.nl/thumbnails/sneeuw-warande/DSC_0313.jpg"/></a></div></div>
<div class="dbg_caption"></div>
</td>
<td>
<div class="dbg_picture_outer"><div class="dbg_picture_inner"><a href="http://martijn.van.steenbergen.nl/galleries/sneeuw-warande/DSC_0316.jpg" rel="lightbox[sneeuw-warande]" title="Looking up at the snowy foliage. Some stars are visible in the sky.">
<img src="http://martijn.van.steenbergen.nl/thumbnails/sneeuw-warande/DSC_0316.jpg" alt="http://martijn.van.steenbergen.nl/thumbnails/sneeuw-warande/DSC_0316.jpg"/></a></div></div>
<div class="dbg_caption">Looking up at the snowy foliage. Some stars are visible in the sky.</div>
</td>
</tr>
</table>

<img src="http://feeds.feedburner.com/~r/MedeaMelana/~4/hBRqHg3yNP8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://martijn.van.steenbergen.nl/journal/2009/12/21/sneeuw-at-warande/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://martijn.van.steenbergen.nl/journal/2009/12/21/sneeuw-at-warande/</feedburner:origLink></item>
		<item>
		<title>Midwinter Fair 2009</title>
		<link>http://feedproxy.google.com/~r/MedeaMelana/~3/PqV4THPvFoo/</link>
		<comments>http://martijn.van.steenbergen.nl/journal/2009/12/13/midwinter-fair-2009/#comments</comments>
		<pubDate>Sun, 13 Dec 2009 22:55:33 +0000</pubDate>
		<dc:creator>Martijn</dc:creator>
				<category><![CDATA[Events]]></category>

		<guid isPermaLink="false">http://martijn.van.steenbergen.nl/journal/?p=454</guid>
		<description><![CDATA[Vandaag nam de Midwinter Fair 2009 plaats in het Archeon in Alphen aan den Rijn. Muziek, dans, markt, vechtshows, ambachten, lezingen en speltoernooien kwamen bijeen op deze zeer succesvolle en gezellige dag. Beter weer hadden de bezoekers zich niet kunnen wensen: winters koud, blauwe lucht en prachtige zonsopkomst en -ondergang.





Erica van Brenk, Lies Sommer en [...]]]></description>
			<content:encoded><![CDATA[<p>Vandaag nam de Midwinter Fair 2009 plaats in het Archeon in Alphen aan den Rijn. Muziek, dans, markt, vechtshows, ambachten, lezingen en speltoernooien kwamen bijeen op deze zeer succesvolle en gezellige dag. Beter weer hadden de bezoekers zich niet kunnen wensen: winters koud, blauwe lucht en prachtige zonsopkomst en -ondergang.</p>
<table cellspacing="0" cellpadding="0" class="dbg_gallery">
<tr>
<td>
<div class="dbg_picture_outer"><div class="dbg_picture_inner"><a href="http://martijn.van.steenbergen.nl/galleries/midwinterfair2009/DSC_9841.jpg" rel="lightbox[midwinterfair2009]" title="Erica van Brenk, Lies Sommer en Marco van Asperen van de folkband Orfeo.">
<img src="http://martijn.van.steenbergen.nl/thumbnails/midwinterfair2009/DSC_9841.jpg" alt="http://martijn.van.steenbergen.nl/thumbnails/midwinterfair2009/DSC_9841.jpg"/></a></div></div>
<div class="dbg_caption">Erica van Brenk, Lies Sommer en Marco van Asperen van de folkband Orfeo.</div>
</td>
<td>
<div class="dbg_picture_outer"><div class="dbg_picture_inner"><a href="http://martijn.van.steenbergen.nl/galleries/midwinterfair2009/DSC_9857.jpg" rel="lightbox[midwinterfair2009]" title="Lies Sommer bespeelt de draailier; in de achtergrond Marco van Asperen op de gitaar.">
<img src="http://martijn.van.steenbergen.nl/thumbnails/midwinterfair2009/DSC_9857.jpg" alt="http://martijn.van.steenbergen.nl/thumbnails/midwinterfair2009/DSC_9857.jpg"/></a></div></div>
<div class="dbg_caption">Lies Sommer bespeelt de draailier; in de achtergrond Marco van Asperen op de gitaar.</div>
</td>
<td>
<div class="dbg_picture_outer"><div class="dbg_picture_inner"><a href="http://martijn.van.steenbergen.nl/galleries/midwinterfair2009/DSC_9866.jpg" rel="lightbox[midwinterfair2009]" title="Paul van de folkband Orfeo op de contrabas.">
<img src="http://martijn.van.steenbergen.nl/thumbnails/midwinterfair2009/DSC_9866.jpg" alt="http://martijn.van.steenbergen.nl/thumbnails/midwinterfair2009/DSC_9866.jpg"/></a></div></div>
<div class="dbg_caption">Paul van de folkband Orfeo op de contrabas.</div>
</td>
<td>
<div class="dbg_picture_outer"><div class="dbg_picture_inner"><a href="http://martijn.van.steenbergen.nl/galleries/midwinterfair2009/DSC_9876.jpg" rel="lightbox[midwinterfair2009]" title="Er werd flink gedanst in de kloosterzaal van het Archeon.">
<img src="http://martijn.van.steenbergen.nl/thumbnails/midwinterfair2009/DSC_9876.jpg" alt="http://martijn.van.steenbergen.nl/thumbnails/midwinterfair2009/DSC_9876.jpg"/></a></div></div>
<div class="dbg_caption">Er werd flink gedanst in de kloosterzaal van het Archeon.</div>
</td>
</tr>
<tr>
<td>
<div class="dbg_picture_outer"><div class="dbg_picture_inner"><a href="http://martijn.van.steenbergen.nl/galleries/midwinterfair2009/DSC_9877.jpg" rel="lightbox[midwinterfair2009]" title="E&eacute;n van de vele marktkraampjes.">
<img src="http://martijn.van.steenbergen.nl/thumbnails/midwinterfair2009/DSC_9877.jpg" alt="http://martijn.van.steenbergen.nl/thumbnails/midwinterfair2009/DSC_9877.jpg"/></a></div></div>
<div class="dbg_caption">E&eacute;n van de vele marktkraampjes.</div>
</td>
<td>
<div class="dbg_picture_outer"><div class="dbg_picture_inner"><a href="http://martijn.van.steenbergen.nl/galleries/midwinterfair2009/DSC_9881.jpg" rel="lightbox[midwinterfair2009]" title="Modellen in het zwart en wit tonen graag hun mooie kleding.">
<img src="http://martijn.van.steenbergen.nl/thumbnails/midwinterfair2009/DSC_9881.jpg" alt="http://martijn.van.steenbergen.nl/thumbnails/midwinterfair2009/DSC_9881.jpg"/></a></div></div>
<div class="dbg_caption">Modellen in het zwart en wit tonen graag hun mooie kleding.</div>
</td>
<td>
<div class="dbg_picture_outer"><div class="dbg_picture_inner"><a href="http://martijn.van.steenbergen.nl/galleries/midwinterfair2009/DSC_9898.jpg" rel="lightbox[midwinterfair2009]" title="Laag, warm zonlicht valt op de muren van deze schuur.">
<img src="http://martijn.van.steenbergen.nl/thumbnails/midwinterfair2009/DSC_9898.jpg" alt="http://martijn.van.steenbergen.nl/thumbnails/midwinterfair2009/DSC_9898.jpg"/></a></div></div>
<div class="dbg_caption">Laag, warm zonlicht valt op de muren van deze schuur.</div>
</td>
<td>
<div class="dbg_picture_outer"><div class="dbg_picture_inner"><a href="http://martijn.van.steenbergen.nl/galleries/midwinterfair2009/DSC_9901.jpg" rel="lightbox[midwinterfair2009]" title="Tussen de huizen in &eacute;&eacute;n van de straten in het Archeon.">
<img src="http://martijn.van.steenbergen.nl/thumbnails/midwinterfair2009/DSC_9901.jpg" alt="http://martijn.van.steenbergen.nl/thumbnails/midwinterfair2009/DSC_9901.jpg"/></a></div></div>
<div class="dbg_caption">Tussen de huizen in &eacute;&eacute;n van de straten in het Archeon.</div>
</td>
</tr>
<tr>
<td>
<div class="dbg_picture_outer"><div class="dbg_picture_inner"><a href="http://martijn.van.steenbergen.nl/galleries/midwinterfair2009/DSC_9908.jpg" rel="lightbox[midwinterfair2009]" title="Verkoop van stenen in een winkeltje.">
<img src="http://martijn.van.steenbergen.nl/thumbnails/midwinterfair2009/DSC_9908.jpg" alt="http://martijn.van.steenbergen.nl/thumbnails/midwinterfair2009/DSC_9908.jpg"/></a></div></div>
<div class="dbg_caption">Verkoop van stenen in een winkeltje.</div>
</td>
<td>
<div class="dbg_picture_outer"><div class="dbg_picture_inner"><a href="http://martijn.van.steenbergen.nl/galleries/midwinterfair2009/DSC_9913.jpg" rel="lightbox[midwinterfair2009]" title="">
<img src="http://martijn.van.steenbergen.nl/thumbnails/midwinterfair2009/DSC_9913.jpg" alt="http://martijn.van.steenbergen.nl/thumbnails/midwinterfair2009/DSC_9913.jpg"/></a></div></div>
<div class="dbg_caption"></div>
</td>
<td>
<div class="dbg_picture_outer"><div class="dbg_picture_inner"><a href="http://martijn.van.steenbergen.nl/galleries/midwinterfair2009/DSC_9972.jpg" rel="lightbox[midwinterfair2009]" title="Vuurspuwers zorgen voor een spetterende vuurshow.">
<img src="http://martijn.van.steenbergen.nl/thumbnails/midwinterfair2009/DSC_9972.jpg" alt="http://martijn.van.steenbergen.nl/thumbnails/midwinterfair2009/DSC_9972.jpg"/></a></div></div>
<div class="dbg_caption">Vuurspuwers zorgen voor een spetterende vuurshow.</div>
</td>
<td>
<div class="dbg_picture_outer"><div class="dbg_picture_inner"><a href="http://martijn.van.steenbergen.nl/galleries/midwinterfair2009/DSC_9991.jpg" rel="lightbox[midwinterfair2009]" title="Vuurspuwers zorgen voor een spetterende vuurshow.">
<img src="http://martijn.van.steenbergen.nl/thumbnails/midwinterfair2009/DSC_9991.jpg" alt="http://martijn.van.steenbergen.nl/thumbnails/midwinterfair2009/DSC_9991.jpg"/></a></div></div>
<div class="dbg_caption">Vuurspuwers zorgen voor een spetterende vuurshow.</div>
</td>
</tr>
<tr>
<td>
<div class="dbg_picture_outer"><div class="dbg_picture_inner"><a href="http://martijn.van.steenbergen.nl/galleries/midwinterfair2009/DSC_0083.jpg" rel="lightbox[midwinterfair2009]" title="Met brandende pijlen werd getracht een haard aan te steken.">
<img src="http://martijn.van.steenbergen.nl/thumbnails/midwinterfair2009/DSC_0083.jpg" alt="http://martijn.van.steenbergen.nl/thumbnails/midwinterfair2009/DSC_0083.jpg"/></a></div></div>
<div class="dbg_caption">Met brandende pijlen werd getracht een haard aan te steken.</div>
</td>
<td>
<div class="dbg_picture_outer"><div class="dbg_picture_inner"><a href="http://martijn.van.steenbergen.nl/galleries/midwinterfair2009/DSC_0028.jpg" rel="lightbox[midwinterfair2009]" title="De haard vat vlam en vuurpijlen schieten omhoog.">
<img src="http://martijn.van.steenbergen.nl/thumbnails/midwinterfair2009/DSC_0028.jpg" alt="http://martijn.van.steenbergen.nl/thumbnails/midwinterfair2009/DSC_0028.jpg"/></a></div></div>
<div class="dbg_caption">De haard vat vlam en vuurpijlen schieten omhoog.</div>
</td>
<td>
<div class="dbg_picture_outer"><div class="dbg_picture_inner"><a href="http://martijn.van.steenbergen.nl/galleries/midwinterfair2009/DSC_0091.jpg" rel="lightbox[midwinterfair2009]" title="E&eacute;n van de winkeltjes.">
<img src="http://martijn.van.steenbergen.nl/thumbnails/midwinterfair2009/DSC_0091.jpg" alt="http://martijn.van.steenbergen.nl/thumbnails/midwinterfair2009/DSC_0091.jpg"/></a></div></div>
<div class="dbg_caption">E&eacute;n van de winkeltjes.</div>
</td>
<td>
<div class="dbg_picture_outer"><div class="dbg_picture_inner"><a href="http://martijn.van.steenbergen.nl/galleries/midwinterfair2009/DSC_0095.jpg" rel="lightbox[midwinterfair2009]" title="Het verlichte klooster bij het vallen van de avond.">
<img src="http://martijn.van.steenbergen.nl/thumbnails/midwinterfair2009/DSC_0095.jpg" alt="http://martijn.van.steenbergen.nl/thumbnails/midwinterfair2009/DSC_0095.jpg"/></a></div></div>
<div class="dbg_caption">Het verlichte klooster bij het vallen van de avond.</div>
</td>
</tr>
<tr>
<td>
<div class="dbg_picture_outer"><div class="dbg_picture_inner"><a href="http://martijn.van.steenbergen.nl/galleries/midwinterfair2009/DSC_0102.jpg" rel="lightbox[midwinterfair2009]" title="Maca&eacute;l van de Keltische folkband Rapalje.">
<img src="http://martijn.van.steenbergen.nl/thumbnails/midwinterfair2009/DSC_0102.jpg" alt="http://martijn.van.steenbergen.nl/thumbnails/midwinterfair2009/DSC_0102.jpg"/></a></div></div>
<div class="dbg_caption">Maca&eacute;l van de Keltische folkband Rapalje.</div>
</td>
<td>
<div class="dbg_picture_outer"><div class="dbg_picture_inner"><a href="http://martijn.van.steenbergen.nl/galleries/midwinterfair2009/DSC_0110.jpg" rel="lightbox[midwinterfair2009]" title="Dieb en William van de Keltische folkband Rapalje.">
<img src="http://martijn.van.steenbergen.nl/thumbnails/midwinterfair2009/DSC_0110.jpg" alt="http://martijn.van.steenbergen.nl/thumbnails/midwinterfair2009/DSC_0110.jpg"/></a></div></div>
<div class="dbg_caption">Dieb en William van de Keltische folkband Rapalje.</div>
</td>
<td>
<div class="dbg_picture_outer"><div class="dbg_picture_inner"><a href="http://martijn.van.steenbergen.nl/galleries/midwinterfair2009/DSC_0114.jpg" rel="lightbox[midwinterfair2009]" title="William van de Keltische folkband Rapalje.">
<img src="http://martijn.van.steenbergen.nl/thumbnails/midwinterfair2009/DSC_0114.jpg" alt="http://martijn.van.steenbergen.nl/thumbnails/midwinterfair2009/DSC_0114.jpg"/></a></div></div>
<div class="dbg_caption">William van de Keltische folkband Rapalje.</div>
</td>
</tr>
</table>

<img src="http://feeds.feedburner.com/~r/MedeaMelana/~4/PqV4THPvFoo" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://martijn.van.steenbergen.nl/journal/2009/12/13/midwinter-fair-2009/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://martijn.van.steenbergen.nl/journal/2009/12/13/midwinter-fair-2009/</feedburner:origLink></item>
		<item>
		<title>GADTs in Haskell 98</title>
		<link>http://feedproxy.google.com/~r/MedeaMelana/~3/xO7P33WBabM/</link>
		<comments>http://martijn.van.steenbergen.nl/journal/2009/11/12/gadts-in-haskell-98/#comments</comments>
		<pubDate>Thu, 12 Nov 2009 11:30:40 +0000</pubDate>
		<dc:creator>Martijn</dc:creator>
				<category><![CDATA[Haskell]]></category>

		<guid isPermaLink="false">http://martijn.van.steenbergen.nl/journal/?p=447</guid>
		<description><![CDATA[Last time we saw how some type classes can be reified to datatypes, transformed in arbitrary ways and then transformed back again to polymorphic types. I briefly mentioned that for some type classes you need GADTs rather than classical ADTs.
The dual to this story holds as well: many (if not all) GADTs can be represented [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://martijn.van.steenbergen.nl/journal/2009/10/18/transforming-polymorphic-values/">Last time</a> we saw how some type classes can be reified to datatypes, transformed in arbitrary ways and then transformed back again to polymorphic types. I briefly mentioned that for some type classes you need GADTs rather than classical ADTs.</p>
<p>The dual to this story holds as well: many (if not all) GADTs can be represented as type classes. To see how, take a look at the standard GADT example:</p>
<pre>
data Term :: * -> * where
  Lit  :: Int        -> Term Int
  Inc  :: Term Int   -> Term Int
  IsZ  :: Term Int   -> Term Bool
  If   :: Term Bool  -> Term a    -> Term a     -> Term a
  Pair :: Term a     -> Term b    -> Term (a,b)
  Fst  :: Term (a,b) -> Term a
  Snd  :: Term (a,b) -> Term b
</pre>
<p>Each constructor result type is indexed by the type of the construct it represents. This example is explained in detail in <a href="http://www.cis.upenn.edu/~dimitriv/wobbly/gadt.pdf">Simple Unification-based Type Inference for GADTs</a> by Simon Peyton Jones et al.</p>
<p>Writing <code>Term</code> like this allows the following well-typed evaluation function:</p>
<pre>
eval :: Term a -> a
eval term = case term of
  Lit n    -> n
  Inc t    -> eval t + 1
  IsZ t    -> eval t == 0
  If c x y -> if eval c then eval x else eval y
  Pair x y -> (eval x, eval y)
  Fst t    -> fst (eval t)
  Snd t    -> snd (eval t)
</pre>
<p>To convert a GADT <code>G</code> to a type class, create a new type class <code>GC</code> with one type parameter <code>g</code>. This type parameter <code>g</code> will have the same kind as <code>G</code>, and its arguments will have the same semantics as those of the <code>G</code>. Then for each constructor create one function in the type class with the exact same type, replacing every occurrence of <code>G</code> by <code>g</code>.</p>
<p>If we follow this recipe for <code>Term</code> we get:</p>
<pre>
class TermC term where
  lit  :: Int         -> term Int
  inc  :: term Int    -> term Int
  isZ  :: term Int    -> term Bool
  if_  :: term Bool   -> term a    -> term a      -> term a
  pair :: term a      -> term b    -> term (a, b)
  fst_ :: term (a, b) -> term a
  snd_ :: term (a, b) -> term b
</pre>
<p>I&#8217;ve used the same names as the constructors except I made them lowercase. I appended <code>_</code> to some to avoid name clashes (<code>fst</code>, <code>snd</code>) or lexical errors (<code>if</code>).</p>
<p>Of course, the <a href="http://martijn.van.steenbergen.nl/journal/2009/10/18/transforming-polymorphic-values/">free instance</a> of <code>TermC</code> is <code>Term</code>.</p>
<p>Now the recipe doesn&#8217;t make any assumptions about the GADT in question, but I don&#8217;t know if this is right, because you can do some powerful things with GADTs. The two special things in datatypes I can think of—class constraints and existentially quantified variables—are no problem in type classes. Also the thing that makes GADTs truly special—custom type indices in constructor result types—have always been allowed in type classes. If I have overlooked something, please let me know and leave a comment.</p>
<p>However, perhaps the more important question is: can we do everything with <code>TermC</code> that we could do with <code>Term</code>? Well, we can certainly implement <code>eval</code>: this becomes a newtype with a corresponding <code>instance TermC</code>:</p>
<pre>
newtype Eval a = Eval { evalC :: a }

instance TermC Eval where
  lit       = Eval
  inc t     = Eval $ evalC t + 1
  isZ t     = Eval $ evalC t == 0
  if_ c x y = Eval $ if evalC c then evalC x else evalC y
  pair x y  = Eval $ (evalC x, evalC y)
  fst_ t    = Eval $ fst (evalC t)
  snd_ t    = Eval $ snd (evalC t)
</pre>
<p>The instance is very, very similar to the original evaluation function. Only instead of recursively calling <code>eval</code>, we call <code>evalC</code> and wrap the result in an <code>Eval</code> constructor. The type of <code>evalC :: Eval a -> a</code> is also similar to <code>eval :: Term a -> a</code>.</p>
<p>What I like most about encoding terms and their evaluation this way is that all the code is Haskell 98!</p>
<p>But not everything is this easy. The step evaluator on the <a href="http://www.haskell.org/haskellwiki/?oldid=29127">Haskell wiki page on GADTs</a>, for example, uses deep pattern matching and as we saw last time this is a lot easier to do on datatypes than in class instances. In fact, I don&#8217;t know if this particular example is possible to translate at all, and if it is, it&#8217;s certainly not going to be Haskell 98.</p>
<p>Another thing GADTs are useful for is witnesses in families of types. Again, I don&#8217;t know if it is possible to translate this use case to class instances.</p>
<p>Summing up, any GADT can be translated to a type class, but not all uses of GADTs have obvious translations. The standard GADT example, however, is trivial to translate. For that reason, it is probably not the most interesting choice as standard example of GADTs.</p>
<img src="http://feeds.feedburner.com/~r/MedeaMelana/~4/xO7P33WBabM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://martijn.van.steenbergen.nl/journal/2009/11/12/gadts-in-haskell-98/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://martijn.van.steenbergen.nl/journal/2009/11/12/gadts-in-haskell-98/</feedburner:origLink></item>
		<item>
		<title>Transforming polymorphic values</title>
		<link>http://feedproxy.google.com/~r/MedeaMelana/~3/UmmZgyHYIbI/</link>
		<comments>http://martijn.van.steenbergen.nl/journal/2009/10/18/transforming-polymorphic-values/#comments</comments>
		<pubDate>Sun, 18 Oct 2009 17:03:08 +0000</pubDate>
		<dc:creator>Martijn</dc:creator>
				<category><![CDATA[Haskell]]></category>

		<guid isPermaLink="false">http://martijn.van.steenbergen.nl/journal/?p=424</guid>
		<description><![CDATA[
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE DeriveDataTypeable #-}

module Arith where

import Data.Generics
import Control.Applicative

Recently there&#8217;s been a bit of talk in the Haskell café about what a DSL is. Robert Atkey gave the nice answer that you can often capture a DSL in one or more type classes, and implementations of this DSL then correspond to instances of [...]]]></description>
			<content:encoded><![CDATA[<pre>
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE DeriveDataTypeable #-}

module Arith where

import Data.Generics
import Control.Applicative
</pre>
<p>Recently there&#8217;s been a bit of talk in the Haskell café about <a href="http://thread.gmane.org/gmane.comp.lang.haskell.cafe/64474">what a DSL is</a>. Robert Atkey gave the <a href="http://thread.gmane.org/gmane.comp.lang.haskell.cafe/64474/focus=64494">nice answer</a> that you can often capture a DSL in one or more type classes, and implementations of this DSL then correspond to instances of these type classes.</p>
<p>Arithmetic expressions with variables, for example, can be captured by this type:</p>
<pre>
type Arith = forall a. (Num a, Var a) => a
</pre>
<p>The <code>Num</code> constraint allows the use of integers and the basic operators, while <code>Var</code> allows the use of variables:</p>
<pre>
class Var a where
  var :: String -> a
</pre>
<p>I would like to show you the various things you can do with a value of type <code>Arith</code>.</p>
<h2>Example <code>Arith</code> values</h2>
<p>Before we do that, however, let&#8217;s think about what this definition of <code>Arith</code> <em>really</em> means. It&#8217;s not any specific type yet, such as <code>Int</code> or <code>Float</code>. Rather, it&#8217;s an expression composed entirely of functions from the <code>Num</code> and <code>Var</code> type classes. Since <code>fromInteger</code> and <code>var</code> are the only functions from those classes that don&#8217;t take recursive values as arguments, calls to those two functions will necessarily make up the leaves of any <code>Arith</code> tree—provided it is finite. Here are some example values:</p>
<pre>
example1 :: Arith
example1 = 1 + 2 * 3

example2 :: Arith
example2 = 2 * var "x" + 0 * var "y"
</pre>
<p>Note that the integer literals in these examples are automatically expanded to calls to <code>fromInteger</code>. To keep the examples somewhat smaller, we will ignore the <code>negate</code>, <code>abs</code> and <code>signum</code> functions from the <code>Num</code> type class. We will also ignore <code>Num</code>&#8217;s superclasses <code>Eq</code> and <code>Show</code>, providing empty instances where necessary; they mess up some of our examples.</p>
<h2>Evaluation as instance</h2>
<p>Now, given values of type <code>Arith</code>, what can we do with them? One thing we can think of is to combine them into a bigger expression:</p>
<pre>
example3 :: Arith
example3 = 6 + example1 - 3 * example2
</pre>
<p>Can we inspect them, or make them smaller? Well, the type is polymorphic, so we can narrow it to a concrete type. We don&#8217;t know any types yet that are instances of both <code>Num</code> and <code>Var</code>, however, so let&#8217;s make one! We&#8217;ll go for one that evaluates the expression, yielding an integer given an environment:</p>
<pre>
newtype Eval = Eval { runEval :: Env -> Integer }
type    Env  = [(String, Integer)]

instance Show Eval
instance Eq Eval

instance Num Eval where
  Eval f + Eval g = Eval (liftA2 (+) f g)
  Eval f * Eval g = Eval (liftA2 (*) f g)
  Eval f - Eval g = Eval (liftA2 (-) f g)
  fromInteger n   = Eval (const n)

instance Var Eval where
  var name = Eval $ \e -> case lookup name e of
    Nothing -> error ("unbound variable: " ++ name)
    Just x -> x
</pre>
<p>Now we can evaluate <code>Arith</code>s simply by calling <code>runExpr</code> on them:</p>
<pre>
*Arith> runEval example1 []
7
*Arith> runEval example2 [("x", 6), ("y", 7)]
12
</pre>
<p>This method of writing functions on <code>Arith</code>s is very much like writing catamorphisms: the tree is reduced to a value, and operands have already had the catamorphisms applied to them recursively, so any computation you want to run on the tree in this way has to be compositional.</p>
<h2>The free instance</h2>
<p>Let&#8217;s do something slightly more complicated: <a href="http://en.wikipedia.org/wiki/Constant_folding">constant folding</a>. The idea of constant folding is to eliminate trivial uses of the operators. <code>x * 0</code>, for example, can be reduced to <code>0</code>, regardless of <code>x</code>&#8217;s value. Other examples are multiplication by 1 and subtraction of 0. Also, if an expression doesn&#8217;t use any variables, we can evaluate it right away.</p>
<p>What type should our constant folding function have? We would expect something like this:</p>
<pre>
foldConstants :: Arith -> Arith
</pre>
<p>Can we write this function as a newtype with instances, too? This turns out to be a lot more difficult. For example, in the case of + we want to inspect the left-hand and right-hand sides to check whether they are zero. But the operands are of type <code>Arith</code>, so we would have to write helper functions such as <code>isZero :: Arith -> Bool</code> which in turn have to be written with new newtypes and instances. This quickly gets out hand. We are running into problems because our catamorphism isn&#8217;t regular anymore.</p>
<p>It would be nice if we could do a &#8216;deep&#8217; inspection of the operands, like we can do when writing functions on normal datatypes. So let&#8217;s do that: make a normal datatype and write our <code>foldConstants</code> on that type.</p>
<pre>
data ReifyArith
  = Add ReifyArith ReifyArith
  | Mul ReifyArith ReifyArith
  | Sub ReifyArith ReifyArith
  | Int Integer
  | Var String
  deriving (Eq, Show, Data, Typeable)

instance Num ReifyArith where
  (+) = Add
  (*) = Mul
  (-) = Sub
  fromInteger = Int

instance Var ReifyArith where
  var = Var
</pre>
<p>I&#8217;ve called this datatype <code>ReifyArith</code> because it reifies an <code>Arith</code> value, turning it into something concrete and tangible. I like to call <code>ReifyArith</code> the <em>free instance</em>, because you can write such a datatype for any combination of classes that adhere to the requirements Robert Atkey mentioned in his email, either as an ADT or a GADT.</p>
<h2>From <code>ReifyArith</code> back to <code>Arith</code></h2>
<p>The nice thing about the free instance is that we do not lose any information: we can easily go back to the polymorphic version of our expressions, like so:</p>
<pre>
generify :: ReifyArith -> Arith
generify expr = case expr of
  Add x y      -> generify x + generify y
  Mul x y      -> generify x * generify y
  Sub x y      -> generify x - generify y
  Int n        -> fromInteger n
  Var name     -> var name
</pre>
<p>Using this technique, we can manipulate <code>Arith</code> values in arbitrary ways. One thing I particularly like is that the <code>ReifyArith</code> is entirely internal to our module and doesn&#8217;t need to be exposed to the outside world.</p>
<h2>Constant folding</h2>
<p>Now that we have a normal datatype, we can write our constant folding transformation. We implement it as a function that does only one step of the rewriting and then use generic programming (<a href="http://www.cs.vu.nl/boilerplate/">Scrap Your Boilerplate</a> in this case) to apply it recursively to our tree. This is why we also derived <code>Data</code> and <code>Typeable</code> for <code>ReifyArith</code>.</p>
<pre>
step :: ReifyArith -> ReifyArith
step expr = case expr of
  -- Reduce computations on integer literals
  Add (Int x) (Int y) -> Int (x + y)
  Mul (Int x) (Int y) -> Int (x * y)
  Sub (Int x) (Int y) -> Int (x - y)

  -- Rewrite rules based on 0 and 1
  Add (Int 0) y -> y
  Add x (Int 0) -> x
  Mul (Int 0) _ -> 0
  Mul _ (Int 0) -> 0
  Mul (Int 1) y -> y
  Mul x (Int 1) -> x
  Sub x (Int 0) -> x

  -- Catch all other cases
  _ -> expr

foldConstants :: Arith -> Arith
foldConstants expr = generify (everywhere (mkT step) expr)
</pre>
<p>Let&#8217;s see if it works:</p>
<pre>
*Arith> foldConstants example1 :: ReifyArith
Int 7
*Arith> foldConstants example2 :: ReifyArith
Mul (Int 2) (Var "x")
</pre>
<p>Indeed, in the first case the transformation is able to fold the entire expression to a single integer literal, and in the second case it has completely eliminated the second term.</p>
<h2>Conclusion</h2>
<p>We have seen that although polymorphic values look abstract and intangible, they are in fact easily manipulated. If a regular, compositional catamorphism is required, the function can be written as instances of the relevant datatypes. If a more complicated, non-regular scheme is required, we can reify the value as a concrete datatype and define the function on that.</p>
<p>Many thanks to <a href="http://w3future.com/">Sjoerd Visscher</a> for valuable feedback!</p>
<img src="http://feeds.feedburner.com/~r/MedeaMelana/~4/UmmZgyHYIbI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://martijn.van.steenbergen.nl/journal/2009/10/18/transforming-polymorphic-values/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		<feedburner:origLink>http://martijn.van.steenbergen.nl/journal/2009/10/18/transforming-polymorphic-values/</feedburner:origLink></item>
		<item>
		<title>Context Synonyms</title>
		<link>http://feedproxy.google.com/~r/MedeaMelana/~3/60i6JB9Fa3o/</link>
		<comments>http://martijn.van.steenbergen.nl/journal/2009/10/11/context-synonyms/#comments</comments>
		<pubDate>Sun, 11 Oct 2009 16:49:49 +0000</pubDate>
		<dc:creator>Martijn</dc:creator>
				<category><![CDATA[Haskell]]></category>

		<guid isPermaLink="false">http://martijn.van.steenbergen.nl/journal/?p=416</guid>
		<description><![CDATA[Sometimes a function&#8217;s type class context grows so big that you would like to group the various type class constraints together and give it a sensible name, especially if that big context is used many times in your module. Consider for example the fold function from module Generics.MultiRec.FoldAlgK:

fold :: (Fam phi, HFunctor phi (PF phi), [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes a function&#8217;s type class context grows so big that you would like to group the various type class constraints together and give it a sensible name, especially if that big context is used many times in your module. Consider for example the <code>fold</code> function from module <code><a href="http://hackage.haskell.org/packages/archive/multirec/0.4/doc/html/Generics-MultiRec-FoldAlgK.html">Generics.MultiRec.FoldAlgK</a></code>:</p>
<pre>
fold :: (Fam phi, HFunctor phi (PF phi), Fold (PF phi)) =>
  Algebra phi r -> phi ix -> ix -> r
</pre>
<p>Context synonyms aim to make it possible to give long contexts a name and reuse it throughout modules. Using a context synonym, the example above can be rewritten to:</p>
<pre>
context FoldFam phi = (Fam phi, HFunctor phi (PF phi), Fold (PF phi))
fold :: FoldFam phi => Algebra phi r -> phi ix -> ix -> r
</pre>
<p>Note that context synonyms are reminiscent of <a href="http://repetae.net/recent/out/classalias.html">class aliases</a>, but that proposal is a lot more involved than this one. Here we are only aiming to give long contexts a convenient short name.</p>
<p>During the <a href="http://www.haskell.org/haskellwiki/Hac5">fifth Haskell Hackathon</a>, a team of programmers (including myself) set out to implement an extension to GHC to make exactly this possible. We were aware of a trick that makes context synonyms already somewhat possible: create a new class and make the right-hand side of the context synonym the superclass constraints of the new type class:</p>
<pre>
class    (Fam phi, HFunctor phi (PF phi), Fold (PF phi)) => FoldFam phi
</pre>
<p>The problem with this approach, however, is that types for which you would like to use the <code>FoldFam</code> constraint are not automatically instances of this new class. Only last week it dawned on me that you can remedy this by supplying one big general instance that makes <em>every</em> type an instance:</p>
<pre>
instance (Fam phi, HFunctor phi (PF phi), Fold (PF phi)) => FoldFam phi
</pre>
<p>Such an instance is sometimes used as in <code>instance Monad f => Applicative f where ...</code>, but this doesn&#8217;t have the desired effect in Haskell. Our <code>FoldFam</code> instance, however, is <em>exactly</em> what we want: match any type with that instance, then check the constraints. This also means we cannot add any more specific instances, which is also what we want.</p>
<p>So it seems we were trying to implement a feature that already sort of exists. To make things worse, Erik pointed out that this use of type classes and instances is documented literally in the <a href="http://www.haskell.org/ghc/docs/6.0/html/users_guide/type-extensions.html#UNDECIDABLE-INSTANCES">GHC docs</a> as old as version 6.0! If only we had known during the Hackathon.</p>
<img src="http://feeds.feedburner.com/~r/MedeaMelana/~4/60i6JB9Fa3o" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://martijn.van.steenbergen.nl/journal/2009/10/11/context-synonyms/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		<feedburner:origLink>http://martijn.van.steenbergen.nl/journal/2009/10/11/context-synonyms/</feedburner:origLink></item>
		<item>
		<title>Heidetuin</title>
		<link>http://feedproxy.google.com/~r/MedeaMelana/~3/v1_zXUb4qA0/</link>
		<comments>http://martijn.van.steenbergen.nl/journal/2009/10/04/heidetuin/#comments</comments>
		<pubDate>Sun, 04 Oct 2009 12:29:36 +0000</pubDate>
		<dc:creator>Martijn</dc:creator>
				<category><![CDATA[Exploring]]></category>

		<guid isPermaLink="false">http://martijn.van.steenbergen.nl/journal/?p=413</guid>
		<description><![CDATA[
There&#8217;s a very pretty piece of forest in Driebergen called the Heidetuin (heath garden). Whenever I&#8217;m in the neighbourhood I pass through it because it&#8217;s so pretty, especially when the sun is out.



























































]]></description>
			<content:encoded><![CDATA[<img class="dbg_single" src="http://martijn.van.steenbergen.nl/galleries/singles/DSC_8136.jpg" alt="DSC_8136.jpg" />
<p>There&#8217;s a very pretty piece of forest in Driebergen called the <em>Heidetuin</em> (heath garden). Whenever I&#8217;m in the neighbourhood I pass through it because it&#8217;s so pretty, especially when the sun is out.</p>
<table cellspacing="0" cellpadding="0" class="dbg_gallery">
<tr>
<td>
<div class="dbg_picture_outer"><div class="dbg_picture_inner"><a href="http://martijn.van.steenbergen.nl/galleries/heidetuin/DSC_8130.jpg" rel="lightbox[heidetuin]" title="">
<img src="http://martijn.van.steenbergen.nl/thumbnails/heidetuin/DSC_8130.jpg" alt="http://martijn.van.steenbergen.nl/thumbnails/heidetuin/DSC_8130.jpg"/></a></div></div>
<div class="dbg_caption"></div>
</td>
<td>
<div class="dbg_picture_outer"><div class="dbg_picture_inner"><a href="http://martijn.van.steenbergen.nl/galleries/heidetuin/DSC_8134.jpg" rel="lightbox[heidetuin]" title="">
<img src="http://martijn.van.steenbergen.nl/thumbnails/heidetuin/DSC_8134.jpg" alt="http://martijn.van.steenbergen.nl/thumbnails/heidetuin/DSC_8134.jpg"/></a></div></div>
<div class="dbg_caption"></div>
</td>
<td>
<div class="dbg_picture_outer"><div class="dbg_picture_inner"><a href="http://martijn.van.steenbergen.nl/galleries/heidetuin/DSC_8136.jpg" rel="lightbox[heidetuin]" title="">
<img src="http://martijn.van.steenbergen.nl/thumbnails/heidetuin/DSC_8136.jpg" alt="http://martijn.van.steenbergen.nl/thumbnails/heidetuin/DSC_8136.jpg"/></a></div></div>
<div class="dbg_caption"></div>
</td>
<td>
<div class="dbg_picture_outer"><div class="dbg_picture_inner"><a href="http://martijn.van.steenbergen.nl/galleries/heidetuin/DSC_8138.jpg" rel="lightbox[heidetuin]" title="">
<img src="http://martijn.van.steenbergen.nl/thumbnails/heidetuin/DSC_8138.jpg" alt="http://martijn.van.steenbergen.nl/thumbnails/heidetuin/DSC_8138.jpg"/></a></div></div>
<div class="dbg_caption"></div>
</td>
</tr>
<tr>
<td>
<div class="dbg_picture_outer"><div class="dbg_picture_inner"><a href="http://martijn.van.steenbergen.nl/galleries/heidetuin/DSC_8139.jpg" rel="lightbox[heidetuin]" title="">
<img src="http://martijn.van.steenbergen.nl/thumbnails/heidetuin/DSC_8139.jpg" alt="http://martijn.van.steenbergen.nl/thumbnails/heidetuin/DSC_8139.jpg"/></a></div></div>
<div class="dbg_caption"></div>
</td>
<td>
<div class="dbg_picture_outer"><div class="dbg_picture_inner"><a href="http://martijn.van.steenbergen.nl/galleries/heidetuin/DSC_8145.jpg" rel="lightbox[heidetuin]" title="">
<img src="http://martijn.van.steenbergen.nl/thumbnails/heidetuin/DSC_8145.jpg" alt="http://martijn.van.steenbergen.nl/thumbnails/heidetuin/DSC_8145.jpg"/></a></div></div>
<div class="dbg_caption"></div>
</td>
<td>
<div class="dbg_picture_outer"><div class="dbg_picture_inner"><a href="http://martijn.van.steenbergen.nl/galleries/heidetuin/DSC_8149.jpg" rel="lightbox[heidetuin]" title="">
<img src="http://martijn.van.steenbergen.nl/thumbnails/heidetuin/DSC_8149.jpg" alt="http://martijn.van.steenbergen.nl/thumbnails/heidetuin/DSC_8149.jpg"/></a></div></div>
<div class="dbg_caption"></div>
</td>
<td>
<div class="dbg_picture_outer"><div class="dbg_picture_inner"><a href="http://martijn.van.steenbergen.nl/galleries/heidetuin/DSC_8154.jpg" rel="lightbox[heidetuin]" title="">
<img src="http://martijn.van.steenbergen.nl/thumbnails/heidetuin/DSC_8154.jpg" alt="http://martijn.van.steenbergen.nl/thumbnails/heidetuin/DSC_8154.jpg"/></a></div></div>
<div class="dbg_caption"></div>
</td>
</tr>
<tr>
<td>
<div class="dbg_picture_outer"><div class="dbg_picture_inner"><a href="http://martijn.van.steenbergen.nl/galleries/heidetuin/DSC_8157.jpg" rel="lightbox[heidetuin]" title="">
<img src="http://martijn.van.steenbergen.nl/thumbnails/heidetuin/DSC_8157.jpg" alt="http://martijn.van.steenbergen.nl/thumbnails/heidetuin/DSC_8157.jpg"/></a></div></div>
<div class="dbg_caption"></div>
</td>
<td>
<div class="dbg_picture_outer"><div class="dbg_picture_inner"><a href="http://martijn.van.steenbergen.nl/galleries/heidetuin/DSC_8163.jpg" rel="lightbox[heidetuin]" title="">
<img src="http://martijn.van.steenbergen.nl/thumbnails/heidetuin/DSC_8163.jpg" alt="http://martijn.van.steenbergen.nl/thumbnails/heidetuin/DSC_8163.jpg"/></a></div></div>
<div class="dbg_caption"></div>
</td>
</tr>
</table>

<img src="http://feeds.feedburner.com/~r/MedeaMelana/~4/v1_zXUb4qA0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://martijn.van.steenbergen.nl/journal/2009/10/04/heidetuin/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://martijn.van.steenbergen.nl/journal/2009/10/04/heidetuin/</feedburner:origLink></item>
		<item>
		<title>let 5 = 6</title>
		<link>http://feedproxy.google.com/~r/MedeaMelana/~3/0DJyD_zzwaU/</link>
		<comments>http://martijn.van.steenbergen.nl/journal/2009/10/02/let-5-6/#comments</comments>
		<pubDate>Fri, 02 Oct 2009 09:31:24 +0000</pubDate>
		<dc:creator>Martijn</dc:creator>
				<category><![CDATA[Haskell]]></category>

		<guid isPermaLink="false">http://martijn.van.steenbergen.nl/journal/?p=405</guid>
		<description><![CDATA[Here&#8217;s a small GHCi session:

Prelude> let 3 - 4 = 5
Prelude> 3 - 4
5
Prelude>

Wait, what? Oh, right, I guess this isn&#8217;t very special: we&#8217;re just redefining the minus operator, and for some very specific input at that.

Prelude> 1 - 2
*** Exception: : Non-exhaustive patterns in function -
Prelude>

Yes, that&#8217;s what we were expecting. How about the [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a small GHCi session:</p>
<pre>
Prelude> let 3 - 4 = 5
Prelude> 3 - 4
5
Prelude>
</pre>
<p>Wait, what? Oh, right, I guess this isn&#8217;t very special: we&#8217;re just redefining the minus operator, and for some very specific input at that.</p>
<pre>
Prelude> 1 - 2
*** Exception: <interactive>: Non-exhaustive patterns in function -
Prelude>
</pre>
<p>Yes, that&#8217;s what we were expecting. How about the following?</p>
<pre>
Prelude> let 5 = 6
Prelude>
</pre>
<p>Wait, what? GHC seems to accept our definition of 5. Have we really redefined 5?</p>
<pre>
Prelude> 5
5
Prelude>
</pre>
<p>No, it seems it&#8217;s just ignored it. What does <code>let 5 = 6</code> mean, then?</p>
<p>To find out, remember that anywhere you define values using <code>=</code>, you may write patterns on the left-hand side, unwrapping constructors and directly naming fields inside. Here&#8217;s an example:</p>
<pre>
Prelude Data.List> let Just ix = elemIndex 'j' ['a'..'z']
Prelude Data.List> ix
9
Prelude Data.List>
</pre>
<p>This works even in a top-level declaration in your module! There&#8217;s no limit to the number of values you may introduce:</p>
<pre>
Prelude> let one : two : three : _ = [1..]
Prelude> (two, three)
(2,3)
Prelude>
</pre>
<p>So if we can introduce any number of values, can we also introduce zero new names?</p>
<pre>
Prelude> let Just True = Nothing
Prelude> let _ = "meep"
Prelude>
</pre>
<p>Yup, those <code>let</code>s are accepted. They just don&#8217;t do anything useful.</p>
<p>Now we can figure out what <code>let 5 = 6</code> means: the pattern on the left-hand side of <code>=</code> contains no new names and so no new names are bound, just like in the example above. This opposed to our very first example, where there is a new name on the left-hand side, namely <code>-</code>.</p>
<p>On a final note, here is what happens when the patterns don&#8217;t match the values on the right-hand side:</p>
<pre>
Prelude> let ('a', b) = ('b', 'c')
Prelude> b
*** Exception: <interactive>: Irrefutable pattern failed for pattern ('a', b)
</pre>
<img src="http://feeds.feedburner.com/~r/MedeaMelana/~4/0DJyD_zzwaU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://martijn.van.steenbergen.nl/journal/2009/10/02/let-5-6/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		<feedburner:origLink>http://martijn.van.steenbergen.nl/journal/2009/10/02/let-5-6/</feedburner:origLink></item>
		<item>
		<title>Stoofpeertjes</title>
		<link>http://feedproxy.google.com/~r/MedeaMelana/~3/wTJ8uMYDJ4I/</link>
		<comments>http://martijn.van.steenbergen.nl/journal/2009/09/25/stoofpeertjes/#comments</comments>
		<pubDate>Fri, 25 Sep 2009 09:08:23 +0000</pubDate>
		<dc:creator>Martijn</dc:creator>
				<category><![CDATA[Food]]></category>

		<guid isPermaLink="false">http://martijn.van.steenbergen.nl/journal/?p=398</guid>
		<description><![CDATA[
On the way from home to university are several farmers that sell part of their produce to people passing by. One of them sells stoofperen (cooking pears) and I couldn&#8217;t resist picking up a bag since I&#8217;d never prepared them before. The toughest part was peeling them—I spent over an hour and a half. But! [...]]]></description>
			<content:encoded><![CDATA[<img class="dbg_single" src="http://martijn.van.steenbergen.nl/galleries/singles/DSC_8127.jpg" alt="DSC_8127.jpg" />
<p>On the way from home to university are several farmers that sell part of their produce to people passing by. One of them sells <em>stoofperen</em> (cooking pears) and I couldn&#8217;t resist picking up a bag since I&#8217;d never prepared them before. The toughest part was peeling them—I spent over an hour and a half. But! The result is well worth it. Three hours of simmering in water and some sugar yielded this beautiful bowl of sweet yummy reddish pears.</p>
<p>Things to remember the next time: 1) use a sharper knife, 2) add a bit less sugar and 3) stir less (or not at all) so that they stay in bigger pieces.</p>
<img src="http://feeds.feedburner.com/~r/MedeaMelana/~4/wTJ8uMYDJ4I" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://martijn.van.steenbergen.nl/journal/2009/09/25/stoofpeertjes/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		<feedburner:origLink>http://martijn.van.steenbergen.nl/journal/2009/09/25/stoofpeertjes/</feedburner:origLink></item>
		<item>
		<title>My Office</title>
		<link>http://feedproxy.google.com/~r/MedeaMelana/~3/CJmmoqVgJ9s/</link>
		<comments>http://martijn.van.steenbergen.nl/journal/2009/08/10/my-office/#comments</comments>
		<pubDate>Mon, 10 Aug 2009 16:21:02 +0000</pubDate>
		<dc:creator>Martijn</dc:creator>
				<category><![CDATA[Random]]></category>

		<guid isPermaLink="false">http://martijn.van.steenbergen.nl/journal/?p=232</guid>
		<description><![CDATA[Below a picture of where I studied today and last Friday. I love it—quiet, serene, with forest and water and ducks all around, and kind people bringing me tea and hot chocolate whenever I ask. The place is called Kraaybeekerhof in Driebergen.

]]></description>
			<content:encoded><![CDATA[<p>Below a picture of where I studied today and last Friday. I love it—quiet, serene, with forest and water and ducks all around, and kind people bringing me tea and hot chocolate whenever I ask. The place is called <a href="http://kraaybeekerhof.nl/">Kraaybeekerhof</a> in Driebergen.</p>
<img class="dbg_single" src="http://martijn.van.steenbergen.nl/galleries/singles/DSC_6875.jpg" alt="DSC_6875.jpg" />
<img src="http://feeds.feedburner.com/~r/MedeaMelana/~4/CJmmoqVgJ9s" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://martijn.van.steenbergen.nl/journal/2009/08/10/my-office/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://martijn.van.steenbergen.nl/journal/2009/08/10/my-office/</feedburner:origLink></item>
	</channel>
</rss>
