<?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>Alson Kemp &#187; Programming</title>
	<atom:link href="http://www.alsonkemp.com/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.alsonkemp.com</link>
	<description>Hackfoofery</description>
	<lastBuildDate>Fri, 16 Jul 2010 18:18:32 +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>Turbinado update</title>
		<link>http://www.alsonkemp.com/haskell/turbinado-update/</link>
		<comments>http://www.alsonkemp.com/haskell/turbinado-update/#comments</comments>
		<pubDate>Thu, 18 Dec 2008 18:13:43 +0000</pubDate>
		<dc:creator>alson</dc:creator>
				<category><![CDATA[Geekery]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Turbinado]]></category>

		<guid isPermaLink="false">http://www.alsonkemp.com/?p=147</guid>
		<description><![CDATA[ For those of you interested in Turbinado, here&#8217;s a quick status update:


    I separated the code for the turbinado.org website from the code for the framework.  The framework is here and the website code is here.
    I&#8217;m going to finish up implementing HAML templating for Turbinado in the [...]]]></description>
			<content:encoded><![CDATA[<p><a href="www.turbinado.org"><img class="alignright" style="margin-left: 10px; margin-right: 10px;" src="http://turbinado.org/images/turbinado.jpg" alt="Turbinado Logo" width="130" height="165" /></a> For those of you interested in <a href="http://turbinado.org" target="_blank">Turbinado</a>, here&#8217;s a quick status update:</p>

<ul>
    <li>I separated the code for the <a href="http://turbinado.org" target="_blank">turbinado.org</a> website from the code for the framework.  The framework is <a href="http://github.com/alsonkemp/turbinado" target="_blank">here</a> and the website code is <a href="http://github.com/alsonkemp/turbinado-website" target="_blank">here</a>.</li>
    <li>I&#8217;m going to finish up implementing HAML templating for Turbinado in the next few days.</li>
    <li>After HAML templates are in, I&#8217;ll provide a tutorial on implementing a mini-CMS/wiki in Turbinado (the code is already in the <a href="http://github.com/alsonkemp/turbinado-website" target="_blank">website</a>.  The standard-Rails-ish &#8220;look, Mom!  No code!&#8221; type of tutorial.  Just enough to convince you to download it, but not enough to get you to be significantly productive.  <img src='http://www.alsonkemp.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </li>
    <li>Adam Stark is providing some greatly needed polish   <a href="http://github.com/llamadonica/turbinado/tree">here</a> as he attempts to get this beastie to build.  Turbinado really needs to be easier to build&#8230;</li>
    <li><a href="http://diegoeche.blogspot.com/" target="_blank">Diego Echeverri</a> is doing some work to get Turbinado to work with GHC 6.10 <a href="http://github.com/diegoeche/turbinado/tree" target="_blank">here.</a> I had a difficult time getting my HSP-ish View templates working with 6.10, so I hope Diego can do it.  I&#8217;d greatly prefer to be working with 6.10, but I couldn&#8217;t get there&#8230;</li>
</ul>

<p>Writing a little web framework turns out to be a lot of work (it&#8217;s all the little stuff (documentation!!) that really gets ya).  I&#8217;ve greatly appreciated the ability to build on the work of others (especially <a href="http://www.cs.chalmers.se/~d00nibro/" target="_blank">Niklas Broberg</a>, <a href="http://www.cse.unsw.edu.au/~dons/" target="_blank">Don Stewart</a>, <a href="http://www.cs.chalmers.se/~bringert/" target="_blank">Bjorn Bringert</a> and <a href="http://www.complete.org/jgoerzen/" target="_blank">John Goerzen</a>) and am grateful that others are providing help to this fledgling project.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alsonkemp.com/haskell/turbinado-update/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>GitHub, &#8216;git&#8217; and the forking fallacy</title>
		<link>http://www.alsonkemp.com/haskell/github-git-and-the-forking-fallacy/</link>
		<comments>http://www.alsonkemp.com/haskell/github-git-and-the-forking-fallacy/#comments</comments>
		<pubDate>Thu, 18 Dec 2008 05:04:43 +0000</pubDate>
		<dc:creator>alson</dc:creator>
				<category><![CDATA[Geekery]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.alsonkemp.com/?p=134</guid>
		<description><![CDATA[GitHub is a pretty sweet system.  One of the best aspects of web 2.0 has been the focus on simple, straightforward web app usability/utility.  GitHub is a great example of some of web 2.0&#8217;s best attributes: a really interesting model coupled with straightforward usability and just a touch of AJAX.  I never would have [...]]]></description>
			<content:encoded><![CDATA[<p><a href="www.github.com">GitHub</a> is a pretty sweet system.  One of the best aspects of <em>web 2.0</em> has been the focus on simple, straightforward web app usability/utility.  <a href="www.github.com">GitHub</a> is a great example of some of <em>web 2.0&#8217;s</em> best attributes: a really interesting model coupled with straightforward usability and <em>just a touch</em> of AJAX.  I never would have tried <a href="http://git.or.cz">Git</a> without  <a href="www.github.com">GitHub</a>.</p>

<p><a href="http://git.or.cz">Git</a> is pretty interesting, too.  Turns out that <a href="http://git.or.cz">git</a> is effective at encouraging social involvement in coding.  The <a href="www.turbinado.org">Turbinado</a> project has been forked a few times&#8230;  &#8216;Forked&#8217;?!  Wait!  That&#8217;s what happens when <a href="http://en.wikipedia.org/wiki/XFree86">projects</a> are in deep trouble, right?!</p>

<p>Maybe so, but not necessarily in <a href="http://git.or.cz">git</a>.  Since <a href="http://git.or.cz">git</a> is a decentralized revision control system (like our beloved <a href="darcs.net/">darcs</a>), &#8216;forking&#8217; is roughly equivalent to &#8216;checking out&#8217;. A &#8216;fork&#8217; is a good thing, so Rails&#8217; fork count (<strong>398</strong>) is <strong>heroic</strong>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alsonkemp.com/haskell/github-git-and-the-forking-fallacy/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Thinking About Haskell*: You Know Lazy Evaluation; You Just Don&#8217;t Know It</title>
		<link>http://www.alsonkemp.com/haskell/thinking-about-haskell-you-know-lazy-evaluation-you-just-dont-know-it/</link>
		<comments>http://www.alsonkemp.com/haskell/thinking-about-haskell-you-know-lazy-evaluation-you-just-dont-know-it/#comments</comments>
		<pubDate>Tue, 16 Dec 2008 05:33:06 +0000</pubDate>
		<dc:creator>alson</dc:creator>
				<category><![CDATA[Geekery]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Lazy Evaluation]]></category>

		<guid isPermaLink="false">http://www.alsonkemp.com/?p=110</guid>
		<description><![CDATA[[Post updated to reflect comments.  ...too much late night typing...]
Lazy evaluation is a very novel aspect of Haskell.  Turns out that it&#8217;s not that difficult to think about.

A very common example of lazy-ish evaluation is &#8216;&#38;&#38;&#8217; operators used in lots of languages (using C#):


if &#40; &#40;obj != null&#41; &#38;&#38; &#40;obj.someMethod&#40;&#41; == somethingElse&#41; &#41; [...]]]></description>
			<content:encoded><![CDATA[<p>[Post updated to reflect comments.  ...too much late night typing...]
Lazy evaluation is a very novel aspect of Haskell.  Turns out that it&#8217;s not that difficult to think about.</p>

<p>A very common example of lazy-ish evaluation is &#8216;&amp;&amp;&#8217; operators used in lots of languages (using C#):</p>


<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#40;</span>obj <span style="color: #008000;">!=</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">&amp;&amp;</span> <span style="color: #000000;">&#40;</span>obj.<span style="color: #0000FF;">someMethod</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">==</span> somethingElse<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
  <span style="color: #008080; font-style: italic;">// do something</span>
<span style="color: #000000;">&#125;</span></pre></div></div>


<p><span id="more-110"></span></p>

<p><em>obj.someMethod</em> isn&#8217;t evaluated unless <em>obj != null</em>.  So <em>&amp;&amp;</em>, a C# function/operator everyone knows and loves, is strict in its first parameter and lazy in its second.  The previous code might act a little like the following:</p>


<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>obj <span style="color: #008000;">!=</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
  <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>obj.<span style="color: #0000FF;">someMethod</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">==</span> somethingElse<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">// do something</span>
  <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>


<p>If <em>&amp;&amp;</em> were strict in both parameters, then it&#8217;d throw errors when the second parameter was unconditionally evaluated (e.g. <em>null.someMethod()).  If _&amp;&amp;</em> weren&#8217;t lazy, it might act something like:</p>


<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">condition1 <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>obj <span style="color: #008000;">!=</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
condition2 <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>obj.<span style="color: #0000FF;">someMethod</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">==</span> somethingElse<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>condition1 <span style="color: #008000;">&amp;&amp;</span> condition2<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">// do something</span>
  <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>


<p>Clearly, <em>condition2</em> would throw an Exception when <em>obj</em> was null, so the <em>if</em> statement must not be evaluating the second parameter.  It&#8217;s as if it were lazy&#8230;</p>

<p>Here&#8217;s the (slightly revised for clarity) definition of <em>&amp;&amp;</em> from Haskell:</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">&amp;&amp;</span><span style="color: green;">&#41;</span>                    <span style="color: #339933; font-weight: bold;">::</span> <span style="color: #cccc00; font-weight: bold;">Bool</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: #cccc00; font-weight: bold;">Bool</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: #cccc00; font-weight: bold;">Bool</span>
<span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">&amp;&amp;</span><span style="color: green;">&#41;</span> True x              <span style="color: #339933; font-weight: bold;">=</span>  x
<span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">&amp;&amp;</span><span style="color: green;">&#41;</span> False <span style="color: #339933; font-weight: bold;">_</span>             <span style="color: #339933; font-weight: bold;">=</span>  False</pre></div></div>


<p>Just as with C#, the first parameter (<em>x</em>) must be evaluated, but the second parameter is only evaluated if the first parameter is True.  <em>&amp;&amp;</em> is <em>strict</em> in the first parameter and <em>lazy</em> in the second.</p>

<h3>And That&#8217;s All There Is to Laziness?</h3>

<p>Nope.  It&#8217;s &#8220;turtles all the way down&#8221;.</p>

<p>Laziness is a defining feature of Haskell and a feature that separates Haskell from the vast majority of languages.  Lazy evaluation isn&#8217;t confined to a few operators in Haskell; lazy evaluation starts at the first function/expression in your program and continues all the way down.</p>

<p>For more reading, check out <a href="http://www.haskell.org/haskellwiki/Haskell/Lazy_evaluation">here</a>, <a href="http://en.wikipedia.org/wiki/Lazy_evaluation">here</a>, <a href="http://neilmitchell.blogspot.com/2008/03/lazy-evaluation-strict-vs-speculative.html">here</a> and <a href="http://www.google.com/search?q=lazy+evaluation+haskell&#038;ie=utf-8&#038;oe=utf-8&#038;aq=t&#038;rls=org.mozilla:en-US:official&#038;client=firefox-a">here</a>.</p>

<h3>But I Don&#8217;t Want To Be Lazy</h3>

<p>[Example fixed.]
Then force evaluation of your parameters.  How?  One way is to use the <em>$!</em> function to force the evaluation of parameters.</p>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">f a b c <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>someFunction <span style="color: #339933; font-weight: bold;">$!</span> a<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">$!</span> b<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">$!</span> c</pre></div></div>


<p>See <a href="http://www.haskell.org/haskellwiki/Performance/Strictness">here</a> for more.</p>

<hr />

<p>&#42; These little bits have helped me think about Haskell.  Maybe they&#8217;ll be useful for you, too.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alsonkemp.com/haskell/thinking-about-haskell-you-know-lazy-evaluation-you-just-dont-know-it/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>A HAML parser for Haskell</title>
		<link>http://www.alsonkemp.com/programming/a-haml-parser-for-haskell/</link>
		<comments>http://www.alsonkemp.com/programming/a-haml-parser-for-haskell/#comments</comments>
		<pubDate>Thu, 11 Dec 2008 05:56:30 +0000</pubDate>
		<dc:creator>alson</dc:creator>
				<category><![CDATA[Geekery]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[HAML]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[Turbinado]]></category>

		<guid isPermaLink="false">http://www.alsonkemp.com/?p=74</guid>
		<description><![CDATA[HAML&#8217;s lovely.  As I&#8217;ve been working with Turbinado,  I&#8217;ve been having some issues with HSP.  HSP is an insanely impressive piece of software, but its error messages can be a bit unclear.   So I started playing around a bit with HAML.  Got me wondering &#8220;How easy would be to [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://haml.hamptoncatlin.com/">HAML</a>&#8217;s lovely.  As I&#8217;ve been working with <a href="http://www.turbinado.org">Turbinado, </a> I&#8217;ve been having some issues with <a href="http://www.cs.chalmers.se/~d00nibro/hsp/">HSP</a>.  HSP is an insanely impressive piece of software, but its error messages can be a bit unclear.   So I started playing around a bit with HAML.  Got me wondering &#8220;How easy would be to write a HAML parser in Haskell?&#8221;</p>

<p>So I tried.  Here&#8217;s a first-pass, to-be-updated [and somewhat incomplete] HAML parser for Haskell. Not all of the features are implemented, but it&#8217;s a start.  It generates <a title="HTML" href="http://hackage.haskell.org/cgi-bin/hackage-scripts/package/xhtml-3000.2.0.1">HTML</a> bits suitable for compilation by GHC.</p>

<h2>Input</h2>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">f <span style="color: #339933; font-weight: bold;">=</span> content
&nbsp;
page <span style="color: #339933; font-weight: bold;">=</span> #content
         <span style="color: #339933; font-weight: bold;">.</span>left<span style="color: #339933; font-weight: bold;">.</span>column
         <span style="color: #339933; font-weight: bold;">%</span>h2 Welcome to our site<span style="color: #339933; font-weight: bold;">!</span>
         <span style="color: #339933; font-weight: bold;">%</span>p <span style="color: #339933; font-weight: bold;">=</span> print<span style="color: #339933; font-weight: bold;">_</span>information
         <span style="color: #339933; font-weight: bold;">%</span>p
           <span style="color: #339933; font-weight: bold;">=</span> print<span style="color: #339933; font-weight: bold;">_</span>inline
         <span style="color: #339933; font-weight: bold;">.</span>right<span style="color: #339933; font-weight: bold;">.</span>column
           <span style="color: #339933; font-weight: bold;">=</span> render
         <span style="color: green;">&#91;</span>abba <span style="color: #339933; font-weight: bold;">=</span> ding<span style="color: #339933; font-weight: bold;">,</span> ding <span style="color: #339933; font-weight: bold;">=</span> abba<span style="color: green;">&#93;</span> dinger</pre></div></div>


<h2>Output</h2>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">f <span style="color: #339933; font-weight: bold;">=</span>
    <span style="color: green;">&#40;</span>stringToHtml <span style="background-color: #3cb371;">&quot;content&quot;</span><span style="color: green;">&#41;</span>
page <span style="color: #339933; font-weight: bold;">=</span>
       <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>tag <span style="background-color: #3cb371;">&quot;div&quot;</span><span style="color: #339933; font-weight: bold;">!</span><span style="color: green;">&#91;</span>strAttr <span style="background-color: #3cb371;">&quot;id&quot;</span> <span style="background-color: #3cb371;">&quot;content&quot;</span><span style="color: green;">&#93;</span><span style="color: green;">&#41;</span>
         <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>tag <span style="background-color: #3cb371;">&quot;div&quot;</span><span style="color: #339933; font-weight: bold;">!</span><span style="color: green;">&#91;</span>strAttr <span style="background-color: #3cb371;">&quot;class&quot;</span> <span style="background-color: #3cb371;">&quot;left column&quot;</span><span style="color: green;">&#93;</span><span style="color: green;">&#41;</span>
         <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>tag <span style="background-color: #3cb371;">&quot;h2&quot;</span><span style="color: green;">&#41;</span>
             <span style="color: green;">&#40;</span>stringToHtml <span style="background-color: #3cb371;">&quot;Welcome to our site!&quot;</span><span style="color: green;">&#41;</span>
         <span style="color: green;">&#41;</span>
         <span style="color: #339933; font-weight: bold;">+++</span>
         <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>tag <span style="background-color: #3cb371;">&quot;p&quot;</span><span style="color: green;">&#41;</span>
            <span style="color: green;">&#40;</span>stringToHtml print<span style="color: #339933; font-weight: bold;">_</span>information<span style="color: green;">&#41;</span>
         <span style="color: green;">&#41;</span>
         <span style="color: #339933; font-weight: bold;">+++</span>
         <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>tag <span style="background-color: #3cb371;">&quot;p&quot;</span><span style="color: green;">&#41;</span>
           <span style="color: green;">&#40;</span>stringToHtml print<span style="color: #339933; font-weight: bold;">_</span>inline<span style="color: green;">&#41;</span>
         <span style="color: green;">&#41;</span>
         <span style="color: #339933; font-weight: bold;">+++</span>
         <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>tag <span style="background-color: #3cb371;">&quot;div&quot;</span><span style="color: #339933; font-weight: bold;">!</span><span style="color: green;">&#91;</span>strAttr <span style="background-color: #3cb371;">&quot;class&quot;</span> <span style="background-color: #3cb371;">&quot;right column&quot;</span><span style="color: green;">&#93;</span><span style="color: green;">&#41;</span>
           <span style="color: green;">&#40;</span>stringToHtml render<span style="color: green;">&#41;</span>
         <span style="color: green;">&#41;</span>
         <span style="color: #339933; font-weight: bold;">+++</span>
         <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>tag <span style="background-color: #3cb371;">&quot;div&quot;</span><span style="color: #339933; font-weight: bold;">!</span><span style="color: green;">&#91;</span>strAttr <span style="background-color: #3cb371;">&quot;abba&quot;</span> <span style="background-color: #3cb371;">&quot;ding&quot;</span><span style="color: #339933; font-weight: bold;">,</span> strAttr <span style="background-color: #3cb371;">&quot;ding&quot;</span> <span style="background-color: #3cb371;">&quot;abba&quot;</span><span style="color: green;">&#93;</span><span style="color: green;">&#41;</span>
                                    <span style="color: green;">&#40;</span>stringToHtml <span style="background-color: #3cb371;">&quot;dinger&quot;</span><span style="color: green;">&#41;</span>
         <span style="color: green;">&#41;</span>
         <span style="color: green;">&#41;</span>
       <span style="color: green;">&#41;</span></pre></div></div>


<h2>le Code</h2>


<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">module</span> Main <span style="color: #06c; font-weight: bold;">where</span>
&nbsp;
<span style="color: #06c; font-weight: bold;">import</span> Text<span style="color: #339933; font-weight: bold;">.</span>ParserCombinators<span style="color: #339933; font-weight: bold;">.</span>Parsec
<span style="color: #06c; font-weight: bold;">import</span> Text<span style="color: #339933; font-weight: bold;">.</span>ParserCombinators<span style="color: #339933; font-weight: bold;">.</span>Parsec<span style="color: #339933; font-weight: bold;">.</span>Language
<span style="color: #06c; font-weight: bold;">import</span> Text<span style="color: #339933; font-weight: bold;">.</span>ParserCombinators<span style="color: #339933; font-weight: bold;">.</span>Parsec<span style="color: #339933; font-weight: bold;">.</span>Pos
<span style="color: #06c; font-weight: bold;">import</span> <span style="color: #06c; font-weight: bold;">qualified</span> Text<span style="color: #339933; font-weight: bold;">.</span>ParserCombinators<span style="color: #339933; font-weight: bold;">.</span>Parsec<span style="color: #339933; font-weight: bold;">.</span>Token <span style="color: #06c; font-weight: bold;">as</span> T
<span style="color: #06c; font-weight: bold;">import</span> Data<span style="color: #339933; font-weight: bold;">.</span><span style="color: #cccc00; font-weight: bold;">Char</span>
<span style="color: #06c; font-weight: bold;">import</span> Data<span style="color: #339933; font-weight: bold;">.</span>List
<span style="color: #06c; font-weight: bold;">import</span> Data<span style="color: #339933; font-weight: bold;">.</span><span style="color: #cccc00; font-weight: bold;">Maybe</span>
<span style="color: #06c; font-weight: bold;">import</span> System<span style="color: #339933; font-weight: bold;">.</span><span style="color: #cccc00; font-weight: bold;">IO</span><span style="color: #339933; font-weight: bold;">.</span>Unsafe
&nbsp;
main <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">do</span> s <span style="color: #339933; font-weight: bold;">&lt;-</span> <span style="font-weight: bold;">getContents</span>
          <span style="color: #06c; font-weight: bold;">case</span> <span style="color: green;">&#40;</span>parse mainParser <span style="background-color: #3cb371;">&quot;stdin&quot;</span> s<span style="color: green;">&#41;</span> <span style="color: #06c; font-weight: bold;">of</span>
            Left  err <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="font-weight: bold;">putStrLn</span> <span style="background-color: #3cb371;">&quot;Error: &quot;</span> <span style="color: #339933; font-weight: bold;">&gt;&gt;</span> <span style="font-weight: bold;">print</span> err
            Right hs  <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="font-weight: bold;">putStrLn</span> hs
&nbsp;
<span style="color: #5d478b; font-style: italic;">-- Try to parse HAML, otherwise re-output raw lines</span>
&nbsp;
mainParser <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">do</span> whiteSpace
                ls <span style="color: #339933; font-weight: bold;">&lt;-</span> many1 <span style="color: green;">&#40;</span>hamlCode <span style="color: #339933; font-weight: bold;">&lt;|&gt;</span> tilEOL<span style="color: green;">&#41;</span>
                <span style="font-weight: bold;">return</span> <span style="color: #339933; font-weight: bold;">$</span> <span style="font-weight: bold;">unlines</span> ls
<span style="color: #5d478b; font-style: italic;">--</span>
<span style="color: #5d478b; font-style: italic;">-- * HAML lexer</span>
<span style="color: #5d478b; font-style: italic;">--</span>
hamlLexer <span style="color: #339933; font-weight: bold;">=</span> T<span style="color: #339933; font-weight: bold;">.</span>makeTokenParser emptyDef
whiteSpace<span style="color: #339933; font-weight: bold;">=</span> T<span style="color: #339933; font-weight: bold;">.</span>whiteSpace hamlLexer
lexeme    <span style="color: #339933; font-weight: bold;">=</span> T<span style="color: #339933; font-weight: bold;">.</span>lexeme hamlLexer
symbol    <span style="color: #339933; font-weight: bold;">=</span> T<span style="color: #339933; font-weight: bold;">.</span>symbol hamlLexer
natural   <span style="color: #339933; font-weight: bold;">=</span> T<span style="color: #339933; font-weight: bold;">.</span>natural hamlLexer
parens    <span style="color: #339933; font-weight: bold;">=</span> T<span style="color: #339933; font-weight: bold;">.</span>parens hamlLexer
semi      <span style="color: #339933; font-weight: bold;">=</span> T<span style="color: #339933; font-weight: bold;">.</span>semi hamlLexer
squares   <span style="color: #339933; font-weight: bold;">=</span> T<span style="color: #339933; font-weight: bold;">.</span>squares hamlLexer
stringLiteral<span style="color: #339933; font-weight: bold;">=</span> T<span style="color: #339933; font-weight: bold;">.</span>stringLiteral hamlLexer
identifier<span style="color: #339933; font-weight: bold;">=</span> T<span style="color: #339933; font-weight: bold;">.</span>identifier hamlLexer
reserved  <span style="color: #339933; font-weight: bold;">=</span> T<span style="color: #339933; font-weight: bold;">.</span>reserved hamlLexer
reservedOp<span style="color: #339933; font-weight: bold;">=</span> T<span style="color: #339933; font-weight: bold;">.</span>reservedOp hamlLexer
commaSep1 <span style="color: #339933; font-weight: bold;">=</span> T<span style="color: #339933; font-weight: bold;">.</span>commaSep1 hamlLexer
<span style="color: #5d478b; font-style: italic;">--</span>
<span style="color: #5d478b; font-style: italic;">-- * Main HAML parsers</span>
<span style="color: #5d478b; font-style: italic;">--</span>
&nbsp;
<span style="color: #5d478b; font-style: italic;">-- hamlCode is just many identifiers (e.g. 'func a b c' followed by '=' followed by a hamlBlock</span>
<span style="color: #5d478b; font-style: italic;">-- func a b c = %somehaml</span>
hamlCode <span style="color: #339933; font-weight: bold;">=</span> try <span style="color: green;">&#40;</span> <span style="color: #06c; font-weight: bold;">do</span> is <span style="color: #339933; font-weight: bold;">&lt;-</span> many1 identifier
                    symbol <span style="background-color: #3cb371;">&quot;=&quot;</span>
                    currentPos <span style="color: #339933; font-weight: bold;">&lt;-</span> getPosition
                    x <span style="color: #339933; font-weight: bold;">&lt;-</span> manyTill1
                          <span style="color: green;">&#40;</span>lexeme <span style="color: #339933; font-weight: bold;">$</span> hamlBlock<span style="color: green;">&#41;</span>
                          <span style="color: green;">&#40;</span>notSameIndent currentPos<span style="color: green;">&#41;</span>
                    <span style="font-weight: bold;">return</span> <span style="color: #339933; font-weight: bold;">$</span> <span style="color: green;">&#40;</span><span style="font-weight: bold;">concat</span> <span style="color: #339933; font-weight: bold;">$</span> intersperse <span style="background-color: #3cb371;">&quot; &quot;</span> is<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">++</span>
                             <span style="background-color: #3cb371;">&quot; = <span style="background-color: #3cb371; font-weight: bold;">\n</span>&quot;</span> <span style="color: #339933; font-weight: bold;">++</span>
                             <span style="color: green;">&#40;</span><span style="font-weight: bold;">concat</span> <span style="color: #339933; font-weight: bold;">$</span> <span style="color: green;">&#40;</span>intersperse <span style="color: green;">&#40;</span>indent currentPos <span style="color: #339933; font-weight: bold;">++</span> <span style="background-color: #3cb371;">&quot;+++<span style="background-color: #3cb371; font-weight: bold;">\n</span>&quot;</span><span style="color: green;">&#41;</span>  <span style="color: #339933; font-weight: bold;">$</span> <span style="font-weight: bold;">filter</span> <span style="color: green;">&#40;</span><span style="font-weight: bold;">not</span> <span style="color: #339933; font-weight: bold;">.</span> <span style="font-weight: bold;">null</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">$</span> x<span style="color: green;">&#41;</span><span style="color: green;">&#41;</span>
                  <span style="color: green;">&#41;</span>
&nbsp;
<span style="color: #5d478b; font-style: italic;">-- A Block may start with some whitespace, then has a valid bit of data</span>
hamlBlock   <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">do</span> currentPos <span style="color: #339933; font-weight: bold;">&lt;-</span> getPosition
                 bs <span style="color: #339933; font-weight: bold;">&lt;-</span> manyTill1
                      <span style="color: green;">&#40;</span>pTag <span style="color: #339933; font-weight: bold;">&lt;|&gt;</span> pText<span style="color: green;">&#41;</span>
                      <span style="color: green;">&#40;</span>notSameIndent currentPos<span style="color: green;">&#41;</span>
                 <span style="font-weight: bold;">return</span> <span style="color: #339933; font-weight: bold;">$</span> intercalate <span style="color: green;">&#40;</span>indent currentPos <span style="color: #339933; font-weight: bold;">++</span> <span style="background-color: #3cb371;">&quot;+++<span style="background-color: #3cb371; font-weight: bold;">\n</span>&quot;</span><span style="color: green;">&#41;</span> bs
&nbsp;
pTag    <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">do</span>    currentPos <span style="color: #339933; font-weight: bold;">&lt;-</span> getPosition
                try
                    <span style="color: green;">&#40;</span><span style="color: #06c; font-weight: bold;">do</span> t  <span style="color: #339933; font-weight: bold;">&lt;-</span> lexeme tagParser
                        ts <span style="color: #339933; font-weight: bold;">&lt;-</span> <span style="color: green;">&#40;</span>isInline currentPos <span style="color: #339933; font-weight: bold;">&gt;&gt;</span> char '<span style="color: #339933; font-weight: bold;">/</span>' <span style="color: #339933; font-weight: bold;">&gt;&gt;</span> <span style="font-weight: bold;">return</span> <span style="color: green;">&#91;</span><span style="color: green;">&#93;</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">&lt;|&gt;</span>
                              <span style="color: green;">&#40;</span>hamlBlock<span style="color: green;">&#41;</span>
                        <span style="font-weight: bold;">return</span> <span style="color: #339933; font-weight: bold;">$</span> intercalate <span style="background-color: #3cb371;">&quot;<span style="background-color: #3cb371; font-weight: bold;">\n</span>&quot;</span> <span style="color: #339933; font-weight: bold;">$</span> <span style="font-weight: bold;">filter</span> <span style="color: green;">&#40;</span><span style="font-weight: bold;">not</span> <span style="color: #339933; font-weight: bold;">.</span> <span style="font-weight: bold;">null</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">$</span>
                          <span style="color: green;">&#91;</span> <span style="color: green;">&#40;</span>indent currentPos<span style="color: green;">&#41;</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> <span style="color: green;">&#40;</span><span style="color: #06c; font-weight: bold;">if</span> <span style="color: green;">&#40;</span><span style="font-weight: bold;">null</span> ts<span style="color: green;">&#41;</span> <span style="color: #06c; font-weight: bold;">then</span> <span style="background-color: #3cb371;">&quot;i&quot;</span> <span style="color: #06c; font-weight: bold;">else</span> <span style="background-color: #3cb371;">&quot;&quot;</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">++</span> t  <span style="color: #339933; font-weight: bold;">++</span> <span style="background-color: #3cb371;">&quot;)&quot;</span>
                          <span style="color: #339933; font-weight: bold;">,</span> <span style="color: #06c; font-weight: bold;">if</span> <span style="font-weight: bold;">null</span> ts <span style="color: #06c; font-weight: bold;">then</span> <span style="color: green;">&#91;</span><span style="color: green;">&#93;</span> <span style="color: #06c; font-weight: bold;">else</span> ts
                          <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span>indent currentPos<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">++</span> <span style="background-color: #3cb371;">&quot;)<span style="background-color: #3cb371; font-weight: bold;">\n</span>&quot;</span><span style="color: green;">&#93;</span>
                    <span style="color: green;">&#41;</span>
&nbsp;
pText <span style="color: #339933; font-weight: bold;">=</span> lexeme stringParser
&nbsp;
notSameIndent p <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#40;</span>eof <span style="color: #339933; font-weight: bold;">&gt;&gt;</span> <span style="font-weight: bold;">return</span> <span style="color: green;">&#91;</span><span style="color: green;">&#93;</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">&lt;|&gt;</span>
                  <span style="color: green;">&#40;</span><span style="color: #06c; font-weight: bold;">do</span> innerPos <span style="color: #339933; font-weight: bold;">&lt;-</span> getPosition
                      <span style="color: #06c; font-weight: bold;">case</span> <span style="color: green;">&#40;</span>sourceColumn p<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">==</span> <span style="color: green;">&#40;</span>sourceColumn innerPos<span style="color: green;">&#41;</span> <span style="color: #06c; font-weight: bold;">of</span>
                                True  <span style="color: #339933; font-weight: bold;">-&gt;</span> pzero
                                False <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="font-weight: bold;">return</span> <span style="color: green;">&#91;</span><span style="color: green;">&#93;</span>
                  <span style="color: green;">&#41;</span>
&nbsp;
<span style="color: #5d478b; font-style: italic;">--</span>
<span style="color: #5d478b; font-style: italic;">-- * Various little parsers</span>
<span style="color: #5d478b; font-style: italic;">--</span>
&nbsp;
tagParser <span style="color: #339933; font-weight: bold;">::</span> CharParser <span style="color: green;">&#40;</span><span style="color: green;">&#41;</span> <span style="color: #cccc00; font-weight: bold;">String</span>
tagParser <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">do</span>     t <span style="color: #339933; font-weight: bold;">&lt;-</span> optionMaybe tagParser'
                   i <span style="color: #339933; font-weight: bold;">&lt;-</span> optionMaybe idParser
                   c <span style="color: #339933; font-weight: bold;">&lt;-</span> optionMaybe <span style="color: green;">&#40;</span>many1 classParser<span style="color: green;">&#41;</span>
                   a <span style="color: #339933; font-weight: bold;">&lt;-</span> optionMaybe attributesParser
                   <span style="color: #06c; font-weight: bold;">if</span> <span style="color: green;">&#40;</span>isJust t <span style="color: #339933; font-weight: bold;">||</span> isJust i <span style="color: #339933; font-weight: bold;">||</span> isJust c <span style="color: #339933; font-weight: bold;">||</span> isJust a<span style="color: green;">&#41;</span>
                     <span style="color: #06c; font-weight: bold;">then</span>
                       <span style="color: #06c; font-weight: bold;">do</span> <span style="font-weight: bold;">return</span> <span style="color: #339933; font-weight: bold;">$</span> <span style="background-color: #3cb371;">&quot;tag <span style="background-color: #3cb371; font-weight: bold;">\&quot;</span>&quot;</span> <span style="color: #339933; font-weight: bold;">++</span> <span style="color: green;">&#40;</span>fromMaybe <span style="background-color: #3cb371;">&quot;div&quot;</span> t<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">++</span> <span style="background-color: #3cb371;">&quot;<span style="background-color: #3cb371; font-weight: bold;">\&quot;</span>&quot;</span> <span style="color: #339933; font-weight: bold;">++</span>
                           <span style="color: green;">&#40;</span><span style="color: #06c; font-weight: bold;">if</span> <span style="font-weight: bold;">not</span> <span style="color: green;">&#40;</span>isJust i <span style="color: #339933; font-weight: bold;">||</span> isJust c <span style="color: #339933; font-weight: bold;">||</span> isJust a<span style="color: green;">&#41;</span> <span style="color: #06c; font-weight: bold;">then</span> <span style="background-color: #3cb371;">&quot;&quot;</span> <span style="color: #06c; font-weight: bold;">else</span>
                              <span style="font-weight: bold;">concat</span> <span style="color: #339933; font-weight: bold;">$</span>
                               <span style="color: green;">&#91;</span> <span style="background-color: #3cb371;">&quot;![&quot;</span>
                               <span style="color: #339933; font-weight: bold;">,</span> intercalate <span style="background-color: #3cb371;">&quot;, &quot;</span> <span style="color: #339933; font-weight: bold;">$</span> <span style="font-weight: bold;">filter</span> <span style="color: green;">&#40;</span><span style="font-weight: bold;">not</span> <span style="color: #339933; font-weight: bold;">.</span> <span style="font-weight: bold;">null</span><span style="color: green;">&#41;</span>
                                   <span style="color: green;">&#91;</span> <span style="color: green;">&#40;</span><span style="font-weight: bold;">maybe</span> <span style="background-color: #3cb371;">&quot;&quot;</span> <span style="color: green;">&#40;</span>\i' <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="background-color: #3cb371;">&quot;strAttr <span style="background-color: #3cb371; font-weight: bold;">\&quot;</span>id<span style="background-color: #3cb371; font-weight: bold;">\&quot;</span> <span style="background-color: #3cb371; font-weight: bold;">\&quot;</span>&quot;</span> <span style="color: #339933; font-weight: bold;">++</span> i' <span style="color: #339933; font-weight: bold;">++</span> <span style="background-color: #3cb371;">&quot;<span style="background-color: #3cb371; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: green;">&#41;</span> i<span style="color: green;">&#41;</span>
                                   <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="font-weight: bold;">maybe</span> <span style="background-color: #3cb371;">&quot;&quot;</span> <span style="color: green;">&#40;</span>\c' <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="background-color: #3cb371;">&quot;strAttr <span style="background-color: #3cb371; font-weight: bold;">\&quot;</span>class<span style="background-color: #3cb371; font-weight: bold;">\&quot;</span> <span style="background-color: #3cb371; font-weight: bold;">\&quot;</span>&quot;</span> <span style="color: #339933; font-weight: bold;">++</span> <span style="color: green;">&#40;</span>intercalate <span style="background-color: #3cb371;">&quot; &quot;</span> c'<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">++</span> <span style="background-color: #3cb371;">&quot;<span style="background-color: #3cb371; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: green;">&#41;</span> c<span style="color: green;">&#41;</span>
                                   <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="font-weight: bold;">maybe</span> <span style="background-color: #3cb371;">&quot;&quot;</span> <span style="color: green;">&#40;</span>\kv <span style="color: #339933; font-weight: bold;">-&gt;</span> intercalate <span style="background-color: #3cb371;">&quot;, &quot;</span> <span style="color: #339933; font-weight: bold;">$</span> <span style="font-weight: bold;">map</span> <span style="color: green;">&#40;</span>\<span style="color: green;">&#40;</span>k<span style="color: #339933; font-weight: bold;">,</span>v<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="background-color: #3cb371;">&quot;strAttr <span style="background-color: #3cb371; font-weight: bold;">\&quot;</span>&quot;</span> <span style="color: #339933; font-weight: bold;">++</span> k <span style="color: #339933; font-weight: bold;">++</span> <span style="background-color: #3cb371;">&quot;<span style="background-color: #3cb371; font-weight: bold;">\&quot;</span> <span style="background-color: #3cb371; font-weight: bold;">\&quot;</span>&quot;</span> <span style="color: #339933; font-weight: bold;">++</span> v <span style="color: #339933; font-weight: bold;">++</span> <span style="background-color: #3cb371;">&quot;<span style="background-color: #3cb371; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: green;">&#41;</span> kv<span style="color: green;">&#41;</span> a<span style="color: green;">&#41;</span>
                                   <span style="color: green;">&#93;</span>
                               <span style="color: #339933; font-weight: bold;">,</span> <span style="background-color: #3cb371;">&quot;]&quot;</span><span style="color: green;">&#93;</span>
                           <span style="color: green;">&#41;</span>
                     <span style="color: #06c; font-weight: bold;">else</span> pzero
&nbsp;
tagParser' <span style="color: #339933; font-weight: bold;">::</span> CharParser <span style="color: green;">&#40;</span><span style="color: green;">&#41;</span> <span style="color: #cccc00; font-weight: bold;">String</span>
tagParser' <span style="color: #339933; font-weight: bold;">=</span>  <span style="color: #06c; font-weight: bold;">do</span> char '<span style="color: #339933; font-weight: bold;">%</span>'
                 many1 termChar
&nbsp;
idParser <span style="color: #339933; font-weight: bold;">::</span> CharParser <span style="color: green;">&#40;</span><span style="color: green;">&#41;</span> <span style="color: #cccc00; font-weight: bold;">String</span>
idParser <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">do</span> char '#'
              many1 termChar
&nbsp;
classParser <span style="color: #339933; font-weight: bold;">::</span> CharParser <span style="color: green;">&#40;</span><span style="color: green;">&#41;</span> <span style="color: #cccc00; font-weight: bold;">String</span>
classParser <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">do</span> char '<span style="color: #339933; font-weight: bold;">.</span>'
                 many1 termChar
&nbsp;
attributesParser <span style="color: #339933; font-weight: bold;">::</span> CharParser <span style="color: green;">&#40;</span><span style="color: green;">&#41;</span> <span style="color: green;">&#91;</span><span style="color: green;">&#40;</span><span style="color: #cccc00; font-weight: bold;">String</span><span style="color: #339933; font-weight: bold;">,</span> <span style="color: #cccc00; font-weight: bold;">String</span><span style="color: green;">&#41;</span><span style="color: green;">&#93;</span>
attributesParser <span style="color: #339933; font-weight: bold;">=</span> squares <span style="color: green;">&#40;</span>commaSep1 attributeParser<span style="color: green;">&#41;</span>
&nbsp;
attributeParser <span style="color: #339933; font-weight: bold;">::</span> CharParser <span style="color: green;">&#40;</span><span style="color: green;">&#41;</span> <span style="color: green;">&#40;</span><span style="color: #cccc00; font-weight: bold;">String</span><span style="color: #339933; font-weight: bold;">,</span> <span style="color: #cccc00; font-weight: bold;">String</span><span style="color: green;">&#41;</span>
attributeParser <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">do</span> k <span style="color: #339933; font-weight: bold;">&lt;-</span> identifier
                     symbol <span style="background-color: #3cb371;">&quot;=&quot;</span>
                     cs <span style="color: #339933; font-weight: bold;">&lt;-</span> many1 identifier
                     <span style="font-weight: bold;">return</span> <span style="color: green;">&#40;</span>k<span style="color: #339933; font-weight: bold;">,</span> intercalate <span style="background-color: #3cb371;">&quot; &quot;</span> cs<span style="color: green;">&#41;</span>
&nbsp;
stringParser <span style="color: #339933; font-weight: bold;">::</span> CharParser <span style="color: green;">&#40;</span><span style="color: green;">&#41;</span> <span style="color: #cccc00; font-weight: bold;">String</span>
stringParser <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">do</span>   currentPos <span style="color: #339933; font-weight: bold;">&lt;-</span> getPosition
                    modifier <span style="color: #339933; font-weight: bold;">&lt;-</span> optionMaybe <span style="color: green;">&#40;</span>char '<span style="color: #339933; font-weight: bold;">=</span>' <span style="color: #339933; font-weight: bold;">&lt;|&gt;</span> char '<span style="color: #339933; font-weight: bold;">-</span>'<span style="color: green;">&#41;</span>
                    whiteSpace
                    c <span style="color: #339933; font-weight: bold;">&lt;-</span> alphaNum
                    cs<span style="color: #339933; font-weight: bold;">&lt;-</span> tilEOL
                    <span style="color: #06c; font-weight: bold;">case</span> modifier <span style="color: #06c; font-weight: bold;">of</span>
                      Just '<span style="color: #339933; font-weight: bold;">-</span>' <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="font-weight: bold;">return</span> <span style="color: #339933; font-weight: bold;">$</span> <span style="color: green;">&#40;</span>indent currentPos<span style="color: green;">&#41;</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> c:cs
                      Just '<span style="color: #339933; font-weight: bold;">=</span>' <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="font-weight: bold;">return</span> <span style="color: #339933; font-weight: bold;">$</span> <span style="color: green;">&#40;</span>indent currentPos<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">++</span> <span style="background-color: #3cb371;">&quot;(stringToHtml &quot;</span> <span style="color: #339933; font-weight: bold;">++</span> c:cs <span style="color: #339933; font-weight: bold;">++</span> <span style="background-color: #3cb371;">&quot;)&quot;</span>
                      Nothing  <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="font-weight: bold;">return</span> <span style="color: #339933; font-weight: bold;">$</span> <span style="color: green;">&#40;</span>indent currentPos<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">++</span> <span style="background-color: #3cb371;">&quot;(stringToHtml <span style="background-color: #3cb371; font-weight: bold;">\&quot;</span>&quot;</span> <span style="color: #339933; font-weight: bold;">++</span> c:cs <span style="color: #339933; font-weight: bold;">++</span> <span style="background-color: #3cb371;">&quot;<span style="background-color: #3cb371; font-weight: bold;">\&quot;</span>)&quot;</span>
&nbsp;
<span style="color: #5d478b; font-style: italic;">--</span>
<span style="color: #5d478b; font-style: italic;">-- * Utility functions</span>
<span style="color: #5d478b; font-style: italic;">--</span>
&nbsp;
isInline     p <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">do</span> p2 <span style="color: #339933; font-weight: bold;">&lt;-</span> getPosition
                    <span style="color: #06c; font-weight: bold;">case</span> <span style="color: green;">&#40;</span>sourceLine p  <span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">==</span> <span style="color: green;">&#40;</span>sourceLine p2<span style="color: green;">&#41;</span> <span style="color: #06c; font-weight: bold;">of</span>
                      True <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="font-weight: bold;">return</span> <span style="color: green;">&#91;</span><span style="color: green;">&#93;</span>
                      False <span style="color: #339933; font-weight: bold;">-&gt;</span> pzero
isSameIndent p1 p2 <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#40;</span>sourceColumn p1<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">==</span> <span style="color: green;">&#40;</span>sourceColumn p2<span style="color: green;">&#41;</span>
&nbsp;
tilEOL <span style="color: #339933; font-weight: bold;">=</span> manyTill1 <span style="color: green;">&#40;</span>noneOf <span style="background-color: #3cb371;">&quot;<span style="background-color: #3cb371; font-weight: bold;">\n</span>&quot;</span><span style="color: green;">&#41;</span> eol
eol <span style="color: #339933; font-weight: bold;">=</span> newline <span style="color: #339933; font-weight: bold;">&lt;|&gt;</span> <span style="color: green;">&#40;</span>eof <span style="color: #339933; font-weight: bold;">&gt;&gt;</span> <span style="font-weight: bold;">return</span> '\n'<span style="color: green;">&#41;</span>
&nbsp;
termChar <span style="color: #339933; font-weight: bold;">=</span> satisfy <span style="color: green;">&#40;</span>\c <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: green;">&#40;</span>isAlphaNum c<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">||</span> <span style="color: green;">&#40;</span>c `<span style="font-weight: bold;">elem</span>` termPunctuation<span style="color: green;">&#41;</span> <span style="color: green;">&#41;</span>
termPunctuation <span style="color: #339933; font-weight: bold;">=</span> <span style="background-color: #3cb371;">&quot;-_&quot;</span>
indent p <span style="color: #339933; font-weight: bold;">=</span> <span style="font-weight: bold;">take</span> <span style="color: green;">&#40;</span>sourceColumn <span style="color: green;">&#40;</span>p<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">-</span> <span style="color: red;">1</span><span style="color: green;">&#41;</span> <span style="color: green;">&#40;</span><span style="font-weight: bold;">repeat</span> ' '<span style="color: green;">&#41;</span>
&nbsp;
manyTill1 p e <span style="color: #339933; font-weight: bold;">=</span>  <span style="color: #06c; font-weight: bold;">do</span> ms <span style="color: #339933; font-weight: bold;">&lt;-</span> manyTill p e
                    <span style="color: #06c; font-weight: bold;">case</span> <span style="color: green;">&#40;</span><span style="font-weight: bold;">null</span> ms<span style="color: green;">&#41;</span> <span style="color: #06c; font-weight: bold;">of</span>
                      True  <span style="color: #339933; font-weight: bold;">-&gt;</span> pzero
                      False <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="font-weight: bold;">return</span> ms</pre></div></div>


<p>Golly, but I wish that I&#8217;d cleaned up the code, but there it is in all of its raw, un-thought-through glory&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alsonkemp.com/programming/a-haml-parser-for-haskell/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>ANNOUNCE: Turbinado V0.2 &#8220;Still Ugly&#8221;</title>
		<link>http://www.alsonkemp.com/work/announce-turbinado-v02-still-ugly/</link>
		<comments>http://www.alsonkemp.com/work/announce-turbinado-v02-still-ugly/#comments</comments>
		<pubDate>Wed, 26 Nov 2008 06:11:59 +0000</pubDate>
		<dc:creator>alson</dc:creator>
				<category><![CDATA[Geekery]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby On rails]]></category>
		<category><![CDATA[Work]]></category>

		<guid isPermaLink="false">http://www.alsonkemp.com/?p=86</guid>
		<description><![CDATA[More progress on Turbinado.  Look!  A whole &#8220;+0.1&#8243;!

Progress continues on Turbinado.  Turbinado can be found at:

http://www.turbinado.org

The source can be found at:

http://github.com/alsonkemp/turbinado/tree/master

   (see the /App directory for the code for www.turbinado.org)

New in V0.2:
  * A better "Environment" type (rather than using Dynamics) (-> a 50%
speed boost?  That's unpossible!);
  [...]]]></description>
			<content:encoded><![CDATA[<p>More progress on Turbinado.  Look!  A whole &#8220;+0.1&#8243;!
<pre>
Progress continues on Turbinado.  Turbinado can be found at:

http://www.turbinado.org</p>

<p>The source can be found at:

http://github.com/alsonkemp/turbinado/tree/master

   (see the /App directory for the code for www.turbinado.org)</p>

<p>New in V0.2:
  * A better "Environment" type (rather than using Dynamics) (-> a 50%
speed boost?  That's unpossible!);
  * A functional early version of an ORM for PostgreSQL (note: still
needs to handle updates; hdbc-postgresql has a bug with sensing
nullable columns);
  * A prettier website;
  * Licensing -> BSD.</p>

<p>Expect V0.3 in the next week or so with:
  * More view helpers;
  * An ORM which handles INSERT/UPDATE...;
  * A little CMS built using the ORM.</p>

<p>Future release:
  * Separate the website out from the framework.  For now, they're
evolving together, so live together. 
</pre></p>
]]></content:encoded>
			<wfw:commentRss>http://www.alsonkemp.com/work/announce-turbinado-v02-still-ugly/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ANNOUNCE: Turbinado V0.1</title>
		<link>http://www.alsonkemp.com/ruby-on-rails/announce-turbinado-v01/</link>
		<comments>http://www.alsonkemp.com/ruby-on-rails/announce-turbinado-v01/#comments</comments>
		<pubDate>Tue, 18 Nov 2008 06:10:33 +0000</pubDate>
		<dc:creator>alson</dc:creator>
				<category><![CDATA[Geekery]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby On rails]]></category>
		<category><![CDATA[Turbinado]]></category>

		<guid isPermaLink="false">http://www.alsonkemp.com/?p=81</guid>
		<description><![CDATA[Posted to the Haskell mailing list:
I'd like to announce Turbinado, a very young and raw MVC web framework
for Haskell.  While the framework doesn't exactly copy Ruby on Rails,
it certainly rhymes...  It's very early days for Turbinado, but the
framework is moving along nicely.  There are still issues to be ironed
out and architectural details to be decided, [...]]]></description>
			<content:encoded><![CDATA[<p>Posted to the <a title="Haskell" href="ANNOUNCE: Turbinado V0.1">Haskell</a> mailing list:
<pre>I'd like to announce Turbinado, a very young and raw MVC web framework
for Haskell.  While the framework doesn't exactly copy Ruby on Rails,
it certainly rhymes...  It's very early days for Turbinado, but the
framework is moving along nicely.  There are still issues to be ironed
out and architectural details to be decided, so help/contribution would be
very much appreciated.</p>

<p>Turbinado can be found at:
<a rel="nofollow" href="http://www.turbinado.org/" target="_top">http://www.turbinado.org</a></p>

<p>The source can be found at:
<a rel="nofollow" href="http://github.com/alsonkemp/turbinado/tree/master" target="_top">http://github.com/alsonkemp/turbinado/tree/master</a>
(see the /App directory for the code for www.turbinado.org)</p>

<p>Turbinado:
* Provides a fast web server (based on HSP; see
<a rel="nofollow" href="http://turbinado.org/Home/Performance%29;" target="_top">http://turbinado.org/Home/Performance);</a>
* Provides a straightforward organization for your website (courtesy
of Rails);
* Uses simple HTML-like templating (courtesy of HSX);
* Is easily extensible (courtesy of an Environment built out of <em>Map
String Dynamic</em>, not the most type-safe of beasties; Help!);
* Configurable routing (see Config/Routes.hs).</p>

<p>Turbinado is currently lacking:
* Documentation...
* An easy install...
* A database ORM based on HDBC (visibly incomplete and ugly in
Turbinado/Database/ORM);
* Many more HTML helpers;
* Controllers for partials (lightweight "controls" ala ASP.NET);
* Strong error reporting and handling;
* Lots of functionality and plugins;
* ... the favorite feature that you want to develop for Turbinado ...</pre></p>
]]></content:encoded>
			<wfw:commentRss>http://www.alsonkemp.com/ruby-on-rails/announce-turbinado-v01/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>6 Sigma vs. 4 Sigma (or Should The Web Be Sloppy?)</title>
		<link>http://www.alsonkemp.com/management/6-sigma-vs-4-sigma-or-should-the-web-be-sloppy/</link>
		<comments>http://www.alsonkemp.com/management/6-sigma-vs-4-sigma-or-should-the-web-be-sloppy/#comments</comments>
		<pubDate>Mon, 01 Sep 2008 18:11:25 +0000</pubDate>
		<dc:creator>alson</dc:creator>
				<category><![CDATA[Management]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[four sigma]]></category>
		<category><![CDATA[six sigma]]></category>

		<guid isPermaLink="false">http://www.alsonkemp.com/?p=9</guid>
		<description><![CDATA[You&#8217;ve probably heard of Six Sigma, the quality management philosophy/practice started at Motorola.  Great way to identify problem areas of product design, development and production.  Sets a goal of having 99.9997% efficiency in the product life cycle.

We have a fairly traditional SDLC process for our web site development and I&#8217;ve been thinking about [...]]]></description>
			<content:encoded><![CDATA[<p>You&#8217;ve probably heard of <a href="http://en.wikipedia.org/wiki/Six_Sigma" target="_blank">Six Sigma</a>, the quality management philosophy/practice started at Motorola.  Great way to identify problem areas of product design, development and production.  Sets a goal of having 99.9997% efficiency in the product life cycle.</p>

<p>We have a fairly traditional <a href="http://en.wikipedia.org/wiki/Systems_Development_Life_Cycle" target="_blank">SDLC</a> process for our web site development and I&#8217;ve been thinking about what the &#8220;right&#8221; process is for our development efforts.  While poking around, I&#8217;ve seen a few blog posts about applying six sigma to <a href="http://www.clickz.com/showPage.html?page=2239681" target="_blank">web marketing</a> or <a href="http://www.roughtype.com/archives/2005/05/six_sigma_softw.php" target="_blank">software development</a>.</p>

<p>Got me thinking: should 6 sigma be applied to web software development?  Maybe 4 sigma would be better?</p>

<p>Really, do I want NetFlix to provide me with 99.9997% quality in their website?  Well, they better handle credit cards with 99.9997% accuracy, but I would prefer that they provide very good quality on their website and focus on rolling out new and improved features.  I wouldn&#8217;t be too irked if their recommendation engine got better and, in return, I saw an occasional visual flaw or 404.  Considering that most web flaws are quickly spotted and easily fixed, it makes some sense to <a href="http://www.catb.org/~esr/writings/cathedral-bazaar/cathedral-bazaar/ar01s04.html" target="_blank">&#8220;release early, release often&#8221;</a>: don&#8217;t overinvest in quality when fixing the issue costs little in terms of time, money or reputation, especially when the benefit of additional features to the user is great.</p>

<p>What about Microsoft Windows?  Unlike a web application, I have to install this bit of software and, unlike a web application, it&#8217;s not easily updated.</p>

<p>So I&#8217;ll vote for Four Sigma quality levels on non-critical areas of consumer websites.  99.379% quality in features is pretty good and I won&#8217;t lose sleep over the 0.621% of features that have some issues&#8230;  But we&#8217;ll commit to fix them ASAP.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alsonkemp.com/management/6-sigma-vs-4-sigma-or-should-the-web-be-sloppy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AJAXing a Conversion Funnel</title>
		<link>http://www.alsonkemp.com/ajax/ajaxing-a-conversion-funnel/</link>
		<comments>http://www.alsonkemp.com/ajax/ajaxing-a-conversion-funnel/#comments</comments>
		<pubDate>Mon, 21 Jul 2008 16:03:58 +0000</pubDate>
		<dc:creator>alson</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[Conversion]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Conversion Funnel]]></category>

		<guid isPermaLink="false">http://www.alsonkemp.com/?p=6</guid>
		<description><![CDATA[Great post about the benefits of using AJAX to shrink a conversion funnel here.

Recently, we were working on a workflow within our site and and spent a bunch of time taking a 6-page funnel down to a pretty AJAXed 3-page funnel.  Got it all tested, put it in production!, and &#8230;no effect on fallout [...]]]></description>
			<content:encoded><![CDATA[<p>Great post about the benefits of using AJAX to shrink a conversion funnel <a title="here" href="http://www.rickwhittington.com/blog/one-page-checkout-flow-using-ajax-boosts-conversion-rates/" target="_blank">here</a>.</p>

<p>Recently, we were working on a workflow within our site and and spent a bunch of time taking a 6-page funnel down to a pretty AJAXed 3-page funnel.  Got it all tested, put it in production!, and &#8230;no effect on fallout in the funnel&#8230;  But, wait, everyone knows that &#8220;making a workflow short and snappy will decrease fallout&#8221;, right?</p>

<p>The explanation we came up with when thinking about the lack of improvement was that we&#8217;d neglected to consider our user&#8217;s motivations &amp; incentives when thinking about our funnel.</p>

<p>The funnel we were working on was a Submit A Review type funnel.  We&#8217;re unusual in that we collect a lot of data from members in that funnel.  We get big, comprehensive reviews from members.  It takes 2-3 minutes to fill out our review form.  Which is awesome for our other members because, when they&#8217;re trying to figure out with whom to spend $75,000 adding a room to their house, they get serious data on the possible contractors.</p>

<p>That said, it&#8217;s kinda hard on the member that&#8217;s submitting the data and the member knows that&#8217;s it&#8217;s going to be hard, so they only enter the funnel if they&#8217;re serious about completing it.  The hard work we did on simplifying the funnel made things easier on the highly-motivated members <em>who were going to submit reports anyway</em>.  Great for the member; not so great for us (ROI ~= 0%).</p>

<p>Why are these members so highly motivated? Our guess is because their incentive to post a review is <em>altruism</em>.  They had a great experience with a service provider or a horrible experience with a service provider and they want to let the other members know.  Posting a review gets them a bit of personal satisfaction.</p>

<p>Naturally, the number of members who are driven by altruism is pretty low.  So if we want to get review submissions up, we need to add other incentives.  The incentive hierarchy probably looks something like: altruism &#8230; reminder/call-to-action &#8230; community/reputation &#8230; chance-to-win-a-prize &#8230; $$$.   As we use other incentives to drive review submissions, the shorter, snapper funnel will help keep fallout low.  So our work wasn&#8217;t for nought&#8230; Just maybe not for much right now&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alsonkemp.com/ajax/ajaxing-a-conversion-funnel/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
