<?xml version="1.0" encoding="UTF-8"?>
<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>lablog</title>
	
	<link>http://blog.typlab.com</link>
	<description>typLAB Blog</description>
	<lastBuildDate>Tue, 23 Feb 2010 09:40:47 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</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/typlab/blog" /><feedburner:info uri="typlab/blog" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Testing Javascript</title>
		<link>http://feedproxy.google.com/~r/typlab/blog/~3/DOqCMRhB_IM/</link>
		<comments>http://blog.typlab.com/2010/02/testing-javascript/#comments</comments>
		<pubDate>Tue, 23 Feb 2010 09:40:47 +0000</pubDate>
		<dc:creator>Erik</dc:creator>
				<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://blog.typlab.com/?p=391</guid>
		<description><![CDATA[At typLAB, we primarily use two programming languages: Javascript and Haskell. Haskell has a compiler, strong static typing, and is pure (no state or side-effects) by default. Javascript, on the other hand, is interpreted, dynamically typed, and, when using objects, uses lots of state (since objects are an encapsulation of state). This makes testing Javascript [...]]]></description>
			<content:encoded><![CDATA[<p>At typLAB, we primarily use two programming languages: Javascript and Haskell. Haskell has a compiler, strong static typing, and is pure (no state or side-effects) by default. Javascript, on the other hand, is interpreted, dynamically typed, and, when using objects, uses lots of state (since objects are an encapsulation of state). This makes testing Javascript more important: otherwise, a typo in a variable name might go undetected until someone uses our product.<br />
<span id="more-391"></span></p>
<p>To test our code, we need a couple of things: we need to write tests, we need a framework to run our tests in, and we need to automatically run this framework regularly. The number of Javascript test frameworks is large these days, and we started by reviewing a few. We finally settled on <a href="http://docs.jquery.com/QUnit">QUnit</a>. It provides a few simple functions to write tests, and a clean and useful page to present the results.</p>
<p>We then integrated QUnit into our work flow. We use a simple, home grown module system to write our Javascript. It uses keywords like <code class="codecolorer text mac-classic"><span class="text">Module</span></code>, <code class="codecolorer text mac-classic"><span class="text">Class</span></code> and <code class="codecolorer text mac-classic"><span class="text">Static</span></code> to easily build modular code. We defined a new annotation, <code class="codecolorer text mac-classic"><span class="text">Test</span></code>, to define a test in a module. All these tests are automatically collected. A separate test runner module imports the modules to test and calls a single function to run all tests in a module.</p>
<p>This provided us with a simple way to write tests. But if this was all, people would forget to run the tests, the tests would start failing without anyone seeing it, and the effort to write the tests would be wasted. To prevent this from happening, we wanted to integrate the running of tests in our work flow. Luckily, <a href="http://ejohn.org/">John Resig</a> has written <a href="http://testswarm.com/">TestSwarm</a>.</p>
<p>Traditionally, integrating Javascript tests in a build process or as a commit hook has been difficult, since Javascript generally depends on the browser to run. Different browsers have different quirks that might make your Javascript behave differently, and your code might also depend on the <abbr title="Document Object Model">DOM</abbr>, which is only available in a browser. However, you don&#8217;t want your developer machine to start many different browsers on each build or commit, and your server might not even have a <abbr title="Graphical User Interface">GUI</abbr>.</p>
<p>TestSwarm is a solution to this problem. It provides a central server, and new tests to be run can be pushed to this server. Clients willing to run tests can also connect to it, and are given tests to run. Results are reported back to the server. This allows TestSwarm to build reports, showing test results per browser for each test run. In our case, our server pushes a new test run to the server on each commit set that is pushed. We have a few browsers open pointing to our TestSwarm instance, which run these tests. This means that testing doesn&#8217;t get in our way, but if something breaks, we can easily see which commit broke it and on which browsers.</p>
<p>The final piece in our testing puzzle takes its inspiration from the Haskell world. <a href="http://www.cs.chalmers.se/~rjmh/QuickCheck/">QuickCheck</a> is a tool that performs randomized testing. You supply a function testing a certain property of your code, and it generates random inputs of increasing size. For example, if you have written a function reversing a list, you can state the property (function) that given a list (the input argument which is randomly generated), reversing it twice produces the original list.</p>
<p>A <a href="http://willowbend.cx/2009/12/05/qc-js-quickcheck-javascript/">Javascript version of QuickCheck</a> exists, and we had a good use case. We use so-called reactive lists, that is, lists which can be connected to keep each other updated. For example, we can create two of these lists, and connect one to the other saying it is always the reverse of the first. When elements are inserted into the first, it sends an event to the second, which processes it, and generates an appropriate insert for the reversed list. The interesting thing is that we have an easily testable static property. Regardless of the mutations on the original list, at any point in time, the reverse of its values must be the same as the values in the output list.</p>
<p>QuickCheck has quickly proven its worth in testing these reactive list functions. Since it generates random values of increasing size, it quickly and reliably finds all the corner cases where bugs like to hide. We&#8217;ve written a small helper function around QuickCheck to integrate it with QUnit, so that we can write code like this:</p>
<pre>
<div class="codecolorer-container javascript mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">function</span> splitTest <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #003366; font-weight: bold;">var</span> l <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> R.<span style="color: #660066;">List</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #003366; font-weight: bold;">var</span> splitfun <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000066; font-weight: bold;">return</span> e <span style="color: #339933;">===</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><br />
&nbsp; <span style="color: #003366; font-weight: bold;">var</span> s <span style="color: #339933;">=</span> l.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span>splitfun<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; quickcheck<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span>arbListOp<span style="color: #009900;">&#40;</span>arbRange<span style="color: #009900;">&#40;</span>0<span style="color: #339933;">,</span> 5<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>c<span style="color: #339933;">,</span> op<span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; op<span style="color: #009900;">&#40;</span>l<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; c.<span style="color: #660066;">assert</span><span style="color: #009900;">&#40;</span>QUnit.<span style="color: #660066;">equiv</span><span style="color: #009900;">&#40;</span>A.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span>splitfun<span style="color: #339933;">,</span> l.<span style="color: #660066;">unR</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> s.<span style="color: #660066;">unR</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
</pre>
<p>This creates two lists: an input list <code class="codecolorer text mac-classic"><span class="text">l</span></code>, and an output list <code class="codecolorer text mac-classic"><span class="text">s</span></code> that is the result of splitting the input list at elements equal to 1. We then call the <code class="codecolorer text mac-classic"><span class="text">quickcheck</span></code> function, which is our helper function. It takes a list of generators as a first argument. In Haskell, these generators can be derived from the types, but here, we have to supply them. In this case, we generate operations on reactive lists. This generator for list operations takes a generator as an argument, which it uses to generate list elements to insert. In this case we generate random integers between 0 and 4 to make sure we get at least a few 1&#8217;s.</p>
<p>The second argument to the <code class="codecolorer text mac-classic"><span class="text">quickcheck</span></code> function is the test function to run. It gets a QuickCheck object as its first argument, followed by the output from all the generators. In this case it gets a function representing an operation on a reactive list. We perform this operation on the input list by calling the function. We then check if the values in the input list (the function <code class="codecolorer text mac-classic"><span class="text">unR</span></code> performs a deep conversion from reactive to normal lists) split on 1&#8217;s are equal to the values in the output list. Here, <code class="codecolorer text mac-classic"><span class="text">A.split</span></code> is a static splitting function, and <code class="codecolorer text mac-classic"><span class="text">QUnit.equiv</span></code> performs a structural equality check on arrays.</p>
<p>Thanks to the availability of these three open source tools, setting all this up only took a few days, and has provided us with a testing setup that works, but doesn&#8217;t get in our way. In the future, we will probably also start testing DOM and user interface related code; hopefully, that will work just as well.</p>
<img src="http://feeds.feedburner.com/~r/typlab/blog/~4/DOqCMRhB_IM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.typlab.com/2010/02/testing-javascript/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://blog.typlab.com/2010/02/testing-javascript/</feedburner:origLink></item>
		<item>
		<title>Reinventing XSLT in pure Javascript</title>
		<link>http://feedproxy.google.com/~r/typlab/blog/~3/pnoizD5u3XY/</link>
		<comments>http://blog.typlab.com/2009/12/reinventing-xslt-in-pure-javascript/#comments</comments>
		<pubDate>Thu, 10 Dec 2009 08:54:07 +0000</pubDate>
		<dc:creator>Sebas</dc:creator>
				<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://blog.typlab.com/?p=188</guid>
		<description><![CDATA[In this post we will explore some boundaries of functional programming in Javascript and show how easy it is to implement a set of combinators that can express functions similar to queries in XPath and similar to transformations in XSLT. We call the result a combinator library because we implement a few primitive queries and [...]]]></description>
			<content:encoded><![CDATA[<p>In this post we will explore some boundaries of functional programming in Javascript and show how easy it is to implement a set of combinators that can express functions similar to queries in XPath and similar to transformations in XSLT. We call the result a <em>combinator</em> library because we implement a few primitive queries and transformations and allow combining these into bigger ones using some basic composition functions. As we will show, all functions will follow more or less the same structure.<br />
<span id="more-188"></span></p>
<p>This post is really about Javascript, which will be the target language of this library. But most of the techniques and underlying thoughts actually come from a statically typed functional programming background. While reading this post it might be interesting to continuously keep in mind the types of the functions, which makes it much easier to understand what is going on and how this framework might be extended with more interesting transformations.</p>
<blockquote><p><em><strong>For the Haskell programmer:</strong></em> the framework we are about to describe here is very similar to the list arrows of the <a href="http://hackage.haskell.org/package/hxt">Haskell XML Toolkit</a>. Looking at the documentation of this package might gain some additional insight.</p></blockquote>
<p>Some functions we will see are selection functions that can be used to select parts of a document, other functions can be seen as filtering functions that exclude parts of the output, some are creation functions that introduce new structure in the output. In these post we call all of these function just <em>transformations</em>. The resulting framework is some hybrid comparable to XPath and XSLT.</p>
<h2>Primitive transformations</h2>
<p>Let&#8217;s first look at the structure of the transformations performed in XPath and XSLT. Both languages can be seen as ways of describing a function that takes <em>one input</em>, the context node, and produces <em>a list of outputs</em>, a node set.  Primitive examples of such transformation functions are: <code class="codecolorer text mac-classic"><span class="text">getChildren</span></code> (<code class="codecolorer text mac-classic"><span class="text">/*</span></code> in XPath), <code class="codecolorer text mac-classic"><span class="text">getParent</span></code> (<code class="codecolorer text mac-classic"><span class="text">..</span></code> in XPath) and <code class="codecolorer text mac-classic"><span class="text">getID</span></code> (<code class="codecolorer text mac-classic"><span class="text">@id</span></code> in XPath).  Implementing these three functions in Javascript is very easy:</p>
<pre>
<div class="codecolorer-container javascript mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">function</span> getChildren <span style="color: #009900;">&#40;</span>ctx<span style="color: #009900;">&#41;</span> toArray<span style="color: #009900;">&#40;</span>ctx.<span style="color: #660066;">childNodes</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #003366; font-weight: bold;">function</span> getParent &nbsp; <span style="color: #009900;">&#40;</span>ctx<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#91;</span>ctx.<span style="color: #660066;">parentNode</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
<span style="color: #003366; font-weight: bold;">function</span> getID &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#40;</span>ctx<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#91;</span>ctx.<span style="color: #660066;">getAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;id&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></div></div>
</pre>
<p>For the ease of reading most functions in this post are written down as Javascript 1.8 lambdas. This syntax, which leaves away the braces and the return statement of functions, is currently only supported by Firefox&#8217;s SpiderMonkey engine. Note that all three functions have exactly the same type, they take one context node as input and return an array of nodes (node set) as output. There is a good reason to have a consistent type signature for these primitive transformations: this allows us to easily compose multiple primitive operations into more advanced transformations.</p>
<h2>Sequential composition</h2>
<p>To illustrate composition, lets see how we would like to write down a transformation that selects all the grandchildren of a context node. Ideally we would like to sequentially compose two invocations of getChildren into one. With sequential composition we mean applying some transformation to the result of some earlier transformation. Something like this:</p>
<pre>
<div class="codecolorer-container javascript mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">var</span> getGrandchildren <span style="color: #339933;">=</span> seq<span style="color: #009900;">&#40;</span>getChildren<span style="color: #339933;">,</span> getChildren<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
</pre>
<p>But what would the <code class="codecolorer text mac-classic"><span class="text">seq</span></code> function look like? To make it more easy to come up with the correct implementation of the <code class="codecolorer text mac-classic"><span class="text">seq</span></code> function it might help to write down the types of all the functions involved and work from there.  We first write down the Haskell style type signatures for our <code class="codecolorer text mac-classic"><span class="text">getChildren</span></code> function, which takes one context node and produces a list of child nodes:</p>
<pre>
<div class="codecolorer-container haskell mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="haskell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">getChildren <span style="color: #339933; font-weight: bold;">::</span> Node <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: green;">&#91;</span>Node<span style="color: green;">&#93;</span></div></div>
</pre>
<p>Because we want the result of the expression <code class="codecolorer text mac-classic"><span class="text">seq(getChildren, getChildren)</span></code> itself to be transformation with the same type again, the type of seq must be:</p>
<pre>
<div class="codecolorer-container haskell mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="haskell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">seq <span style="color: #339933; font-weight: bold;">::</span> <span style="color: green;">&#40;</span>Node <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: green;">&#91;</span>Node<span style="color: green;">&#93;</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: green;">&#40;</span>Node <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: green;">&#91;</span>Node<span style="color: green;">&#93;</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: green;">&#40;</span>Node <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: green;">&#91;</span>Node<span style="color: green;">&#93;</span><span style="color: green;">&#41;</span></div></div>
</pre>
<p>Which means: take two transformations as input and produce one transformation as output. By only looking at the type we can already deduce the following skeleton of the seq function:</p>
<pre>
<div class="codecolorer-container javascript mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">function</span> seq <span style="color: #009900;">&#40;</span>tr0<span style="color: #339933;">,</span> tr1<span style="color: #009900;">&#41;</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>ctx<span style="color: #009900;">&#41;</span> <span style="color: #009966; font-style: italic;">/* [some nodes] */</span> <span style="color: #339933;">;</span></div></div>
</pre>
<p>Note that this function is higher-order, it takes two functions and returns a new function. Now we only have to fill in the gap, which we can do by looking at the desired semantics. In the case of the <code class="codecolorer text mac-classic"><span class="text">getGrandChildren</span></code> function we want to apply the first <code class="codecolorer text mac-classic"><span class="text">getChildren</span></code> transformation to the context node and then apply the second transformation (<code class="codecolorer text mac-classic"><span class="text">getChildren</span></code> again) over all the results of the first transformation and group together the results. Translating this to code would become something like: apply <code class="codecolorer text mac-classic"><span class="text">tr0</span></code> to <code class="codecolorer text mac-classic"><span class="text">ctx</span></code>, than <code class="codecolorer text mac-classic"><span class="text">map</span></code> <code class="codecolorer text mac-classic"><span class="text">tr1</span></code> over all these results and <code class="codecolorer text mac-classic"><span class="text">concat</span></code>the output.</p>
<pre>
<div class="codecolorer-container javascript mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">function</span> seq<span style="color: #009900;">&#40;</span>tr0<span style="color: #339933;">,</span> tr1<span style="color: #009900;">&#41;</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>ctx<span style="color: #009900;">&#41;</span> concat<span style="color: #009900;">&#40;</span>tr0<span style="color: #009900;">&#40;</span>ctx<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">map</span><span style="color: #009900;">&#40;</span>tr1<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #003366; font-weight: bold;">function</span> concat <span style="color: #009900;">&#40;</span>xs<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">concat</span>.<span style="color: #660066;">apply</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> xs<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// stand-alone concat</span></div></div>
</pre>
<p>Now we worked out the skeleton of the function by looking at the derived type and we have come up with an implementation by looking at the desired semantics. The function is now both type correct and works as expected!</p>
<blockquote><p><em><strong>For the Haskell programmer:</strong></em> we just worked out Kleisli composition for the list monad. This composition internally uses the monadic bind for the list monad instance, which happens to be the <code class="codecolorer text mac-classic"><span class="text">concatMap</span></code> function.  The <code class="codecolorer text mac-classic"><span class="text">concatMap</span></code> function has type <code class="codecolorer text mac-classic"><span class="text">[a] -&gt; (a -&gt; [b]) -&gt; [b]</span></code>, which (in our context) shows exactly how we apply a transformation (<code class="codecolorer text mac-classic"><span class="text">a -&gt; [b]</span></code>) to the results of another transformation (<code class="codecolorer text mac-classic"><span class="text">[a]</span></code>) and come up with the result of the composition (<code class="codecolorer text mac-classic"><span class="text">[b]</span></code>).</p></blockquote>
<p>To illustrate the generic behavior of our sequential composition we use it to define some other useful transformations.</p>
<pre>
<div class="codecolorer-container javascript mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">getSiblings &nbsp; &nbsp;<span style="color: #339933;">=</span> seq<span style="color: #009900;">&#40;</span>getParent<span style="color: #339933;">,</span> getChildren<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
getGrandParent <span style="color: #339933;">=</span> seq<span style="color: #009900;">&#40;</span>getParent<span style="color: #339933;">,</span> getParent<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
</pre>
<h2>Alternative composition</h2>
<p>Now we have defined sequential composition we can also try to define another form of composition which just sums up the results of two transformations working over the same context node. For example when we want to create a transformation that selects <em>both</em> the grand parent and the grand children of a context node, we might want to write down something like this:</p>
<pre>
<div class="codecolorer-container javascript mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">getGrands <span style="color: #339933;">=</span> alt<span style="color: #009900;">&#40;</span>getGrandParent<span style="color: #339933;">,</span> getGrandChildren<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
</pre>
<p>We call this composition function <code class="codecolorer text mac-classic"><span class="text">alt</span></code> because it combines two alternative transformation paths into one. The type signature of the <code class="codecolorer text mac-classic"><span class="text">alt</span></code> function is similar to that of <code class="codecolorer text mac-classic"><span class="text">seq</span></code>, it takes two transformations as input and is itself again a transformation. The semantics of this transformation combinator is really easy, it just applies the two input transformation to the same context node and groups the results.</p>
<div class="codecolorer-container javascript mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">function</span> alt<span style="color: #009900;">&#40;</span>tr0<span style="color: #339933;">,</span> tr1<span style="color: #009900;">&#41;</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>ctx<span style="color: #009900;">&#41;</span> concat<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span>tr0<span style="color: #009900;">&#40;</span>ctx<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> tr1<span style="color: #009900;">&#40;</span>ctx<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<blockquote><p><em><strong>For the Haskell programmer:</strong></em> we just worked out the <code class="codecolorer text mac-classic"><span class="text">&lt;+&gt;</span></code> function of the <code class="codecolorer text mac-classic"><span class="text">ArrowPlus</span></code> instance for the list arrow. This function is defined in terms of the <code class="codecolorer text mac-classic"><span class="text">append</span></code> function for lists, with type <code class="codecolorer text mac-classic"><span class="text">[a] -&gt; [a] -&gt; [a]</span></code>. The semantics are very similar to that of the <code class="codecolorer text mac-classic"><span class="text">Alternative</span></code> and <code class="codecolorer text mac-classic"><span class="text">MonadPlus</span></code> type classes. Where the <code class="codecolorer text mac-classic"><span class="text">seq</span></code> function is the algebraic <em>and, product, sequence, <code class="codecolorer text mac-classic"><span class="text">/</span></code>, times, etc</em>, the <code class="codecolorer text mac-classic"><span class="text">alt</span></code> function is the algebraic <em>or, sum, alternative, <code class="codecolorer text mac-classic"><span class="text">|</span></code>, plus, etc</em>.</p></blockquote>
<h2>Deep recursion, filtering and creating.</h2>
<p>Now we have two basic transformation combinators: sequential and alternative composition. Combining these two functions can get us some powerful transformation combinators. E.g. we can make the deep function that applies a transformation at arbitrary depth in document.</p>
<pre>
<div class="codecolorer-container javascript mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">function</span> deep <span style="color: #009900;">&#40;</span>tr<span style="color: #009900;">&#41;</span> alt<span style="color: #009900;">&#40;</span>tr<span style="color: #339933;">,</span> seq<span style="color: #009900;">&#40;</span>getChildren<span style="color: #339933;">,</span> lazy<span style="color: #009900;">&#40;</span>deep<span style="color: #339933;">,</span> tr<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #003366; font-weight: bold;">function</span> lazy <span style="color: #009900;">&#40;</span>f<span style="color: #339933;">,</span> a<span style="color: #009900;">&#41;</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>n<span style="color: #009900;">&#41;</span> f<span style="color: #009900;">&#40;</span>a<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>n<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// postponed function application</span></div></div>
</pre>
<p>The deep function applies a transformation and groups the results with a recursive deep invocation for all the child nodes of the current context. Because, unfortunately, JavaScript is a strict language we have to explicitly delay the recursion in order to prevent infinite loops. Before we will test the deep transformation combinator we define three other useful primitive transformations.</p>
<pre>
<div class="codecolorer-container javascript mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">function</span> self <span style="color: #009900;">&#40;</span>ctx<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#91;</span>ctx<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></div></div>
</pre>
<p>This transformation <code class="codecolorer text mac-classic"><span class="text">self</span></code> is a bit special, it is the identity transformation which outputs a singleton list containing the context node itself. This transformation can be compared to the dot (.) in XPath.</p>
<pre>
<div class="codecolorer-container javascript mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">function</span> isElem <span style="color: #009900;">&#40;</span><span style="color: #000066;">name</span><span style="color: #009900;">&#41;</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>ctx<span style="color: #009900;">&#41;</span> ctx.<span style="color: #660066;">nodeName</span> <span style="color: #339933;">==</span> <span style="color: #000066;">name</span> <span style="color: #339933;">?</span> <span style="color: #009900;">&#91;</span>ctx<span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></div></div>
</pre>
<p>This function <code class="codecolorer text mac-classic"><span class="text">isElem</span></code> is a filter transformation function which includes or excludes a context node based on the <code class="codecolorer text mac-classic"><span class="text">nodeName</span></code>. When the node name matches it is included as a singleton list, when there is no match the empty lists will be returned.</p>
<pre>
<div class="codecolorer-container javascript mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">function</span> mkElem <span style="color: #009900;">&#40;</span><span style="color: #000066;">name</span><span style="color: #009900;">&#41;</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>tr<span style="color: #009900;">&#41;</span><br />
&nbsp; <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>ctx<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#91;</span>createElemWithChildren<span style="color: #009900;">&#40;</span><span style="color: #000066;">name</span><span style="color: #339933;">,</span> tr<span style="color: #009900;">&#40;</span>ctx<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></div></div>
</pre>
<p>The third function <code class="codecolorer text mac-classic"><span class="text">mkElem</span></code> is neither a selection or filtering functions, it is a creation function which takes the output node set of a transformation and surrounds it with a new element. This element will be returned as a singleton node set again.</p>
<p>Using the set of primitives and combinators to create a transformation that produces a simple table of contents from an input document is now very easy. The following transformation shows how to select all <code class="codecolorer text mac-classic"><span class="text">H1</span></code> and <code class="codecolorer text mac-classic"><span class="text">H2</span></code> elements from the entire document. All headers will be surrounded by a <code class="codecolorer text mac-classic"><span class="text">LI</span></code> and inserted into an unordered list <code class="codecolorer text mac-classic"><span class="text">UL</span></code>.</p>
<pre>
<div class="codecolorer-container javascript mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">var</span> isHeader <span style="color: #339933;">=</span> sum<span style="color: #009900;">&#40;</span>isElem<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;h1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> isElem<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;h2&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #003366; font-weight: bold;">var</span> toc <span style="color: #339933;">=</span> mkElem<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;ul&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>seq<span style="color: #009900;">&#40;</span>deep<span style="color: #009900;">&#40;</span>isHeader<span style="color: #339933;">,</span> mkElem<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;li&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>self<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #003366; font-weight: bold;">var</span> myToc <span style="color: #339933;">=</span> toc<span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">body</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
</pre>
<p>Now <code class="codecolorer text mac-classic"><span class="text">toc</span></code> is a true JavaScript function that computes a table of contents from an input document.</p>
<h2>Comparison to XPath</h2>
<p>Here is a (far from complete) table showing a comparison between XPath queries and our transformation functions. With the very few combinators defined, we can already rebuild a powerful set of XPath queries. Some primitives shown below, like <code class="codecolorer text mac-classic"><span class="text">hasAttr</span></code> and <code class="codecolorer text mac-classic"><span class="text">precedingSiblings</span></code>, have not been defined in this post. Defining them is very easy, please try it for yourself and see how far you can get with other exotic XPath axes.</p>
<table style="width: 100%;" border="0">
<thead>
<tr>
<th>XPath</th>
<th>JavaScript</th>
</tr>
</thead>
<tbody>
<tr>
<td><code class="codecolorer text mac-classic"><span class="text">.</span></code></td>
<td><code class="codecolorer text mac-classic"><span class="text">self</span></code></td>
</tr>
<tr>
<td><code class="codecolorer text mac-classic"><span class="text">//div</span></code></td>
<td><code class="codecolorer text mac-classic"><span class="text">deep(isElem(&quot;div&quot;))</span></code></td>
</tr>
<tr>
<td><code class="codecolorer text mac-classic"><span class="text">/*/p</span></code></td>
<td><code class="codecolorer text mac-classic"><span class="text">seq(getChildren, isElem(&quot;p&quot;))</span></code></td>
</tr>
<tr>
<td><code class="codecolorer text mac-classic"><span class="text">(//div|//p)</span></code></td>
<td><code class="codecolorer text mac-classic"><span class="text">sum(deep(isElem(&quot;div&quot;)), deep(isElem(&quot;p&quot;)))</span></code></td>
</tr>
<tr>
<td><code class="codecolorer text mac-classic"><span class="text">//p/../..</span></code></td>
<td><code class="codecolorer text mac-classic"><span class="text">deep(seq(seq(isElem(&quot;p&quot;),<br />
getParent), getParent))</span></code></td>
</tr>
<tr>
<td><code class="codecolorer text mac-classic"><span class="text">/p[@href]/em</span></code></td>
<td><code class="codecolorer text mac-classic"><span class="text">seq(seq(isElem(&quot;p&quot;), hasAttr(&quot;href&quot;))<br />
, seq(getChildren, isElem(&quot;em&quot;)))</span></code></td>
</tr>
<tr>
<td><code class="codecolorer text mac-classic"><span class="text">//table/preceding-sibling::h2</span></code></td>
<td><code class="codecolorer text mac-classic"><span class="text">deep(seq(isElem(&quot;table&quot;),<br />
seq(precedingSiblings, isElem(&quot;h2&quot;))))</span></code></td>
</tr>
</tbody>
</table>
<h2>Conclusion and goal</h2>
<p>So we have seen how easy it is to create a powerful XML query and transformation language with a bare minimum of code. The trick is to define some primitive transformation functions and only two powerful ways to compose transformations. By using functions from one context node to a list of outputs selecting, filtering and creating elements all becomes possible. Using the composition functions you can easily build more advanced and high-level transformations like the <code class="codecolorer text mac-classic"><span class="text">deep</span></code> function that traverses an entire document tree. The comparison between XPath and the selection primitives is quite clear. Adding an element creation function shows that the query language can quite easily become a true transformation language in which we can add new structure to the output.</p>
<p>While building such a library yourself is fun, it might feel a bit useless at first sight. Why reinvent XPath or XSLT while most browsers have built-in support for these tools? There are two main reasons to perform transformations this way.</p>
<p>The first reason is that is now very easy to add extra power to the library by plugging in new JavaScript functions. Using XSLT as a programming language, which unfortunately happens a lot in practice, almost always ends up shooting yourself in the foot with large and unmanageable recursive templates that fuzz what is really going on.</p>
<p>The second reason is more subtle. Here at typLAB we have shown that it is possible to change the primitive transformations and the two composition functions with their <em>functional reactive</em> counterparts. This enables us to incrementally rebuild the output of a transformation when only small parts of the input document change. This incremental reactivity is an extremely powerful paradigm that allows for very fast live queries over semantic and structured documents.</p>
<p>As you can see, this framework is very simple. Try playing with it yourself!</p>
<img src="http://feeds.feedburner.com/~r/typlab/blog/~4/pnoizD5u3XY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.typlab.com/2009/12/reinventing-xslt-in-pure-javascript/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		<feedburner:origLink>http://blog.typlab.com/2009/12/reinventing-xslt-in-pure-javascript/</feedburner:origLink></item>
		<item>
		<title>Writing a generic XML pickler</title>
		<link>http://feedproxy.google.com/~r/typlab/blog/~3/FB7iN7BZQOo/</link>
		<comments>http://blog.typlab.com/2009/11/writing-a-generic-xml-pickler/#comments</comments>
		<pubDate>Tue, 10 Nov 2009 07:57:31 +0000</pubDate>
		<dc:creator>Erik</dc:creator>
				<category><![CDATA[Haskell]]></category>

		<guid isPermaLink="false">http://blog.typlab.com/?p=102</guid>
		<description><![CDATA[In a previous post, Sebas explained that we use so-called XML picklers to convert Haskell data types to XML. Since these picklers have a regular structure, we don&#8217;t write them by hand, but derive them automatically using generic programming techniques. In this post, I&#8217;ll explain how our generic XML pickler works. The code shown here [...]]]></description>
			<content:encoded><![CDATA[<p>In a <a href="http://blog.typlab.com/2009/09/haskell-data-types-and-xml/">previous post</a>, Sebas explained that we use so-called XML picklers to convert Haskell data types to XML. Since these picklers have a regular structure, we don&#8217;t write them by hand, but derive them automatically using generic programming techniques. In this post, I&#8217;ll explain how our generic XML pickler works. The code shown here has been made <a href="http://hackage.haskell.org/package/regular-xmlpickler">available on hackage</a>.<br />
<span id="more-102"></span><br />
We use the <a href="http://hackage.haskell.org/package/regular">regular library</a> to represent data types generically. It allows you to build a structure for your type that is isomorphic to your type, but built up from standard building blocks, called functors. This is possible because Haskell data types have a standard structure: a choice of one of several constructors (this is often called a sum), each having a number of fields (this is often called a product).</p>
<p>As an example, we will represent a simple user data type:</p>
<pre>
<div class="codecolorer-container haskell mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="haskell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #06c; font-weight: bold;">data</span> User <span style="color: #339933; font-weight: bold;">=</span> User<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: green;">&#123;</span> name &nbsp;<span style="color: #339933; font-weight: bold;">::</span> String<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933; font-weight: bold;">,</span> email <span style="color: #339933; font-weight: bold;">::</span> String<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933; font-weight: bold;">,</span> admin <span style="color: #339933; font-weight: bold;">::</span> Bool<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: green;">&#125;</span></div></div>
</pre>
<p>The generic representation of this type is called a pattern functor. For the user data type, it will look like this:</p>
<pre>
<div class="codecolorer-container haskell mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="haskell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #06c; font-weight: bold;">type</span> <span style="color: #06c; font-weight: bold;">instance</span> PF User <span style="color: #339933; font-weight: bold;">=</span> C User<span style="color: #339933; font-weight: bold;">_</span>User<span style="color: #339933; font-weight: bold;">_</span><br />
&nbsp; <span style="color: green;">&#40;</span> &nbsp; S User<span style="color: #339933; font-weight: bold;">_</span>User<span style="color: #339933; font-weight: bold;">_</span>name<span style="color: #339933; font-weight: bold;">_</span> &nbsp;<span style="color: green;">&#40;</span>K String<span style="color: green;">&#41;</span><br />
&nbsp; :<span style="color: #339933; font-weight: bold;">*</span>: S User<span style="color: #339933; font-weight: bold;">_</span>User<span style="color: #339933; font-weight: bold;">_</span>email<span style="color: #339933; font-weight: bold;">_</span> <span style="color: green;">&#40;</span>K String<span style="color: green;">&#41;</span><br />
&nbsp; :<span style="color: #339933; font-weight: bold;">*</span>: S User<span style="color: #339933; font-weight: bold;">_</span>User<span style="color: #339933; font-weight: bold;">_</span>admin &nbsp;<span style="color: green;">&#40;</span>K Bool<span style="color: green;">&#41;</span><br />
&nbsp; <span style="color: green;">&#41;</span></div></div>
</pre>
<p>Here we see a few of the functors that are the building blocks of our generic representation: The <code class="codecolorer text mac-classic"><span class="text">C</span></code> type marks constructors, the <code class="codecolorer text mac-classic"><span class="text">S</span></code> type marks record labels, <code class="codecolorer text mac-classic"><span class="text">K</span></code> marks the types that make up the fields of our record, and <code class="codecolorer text mac-classic"><span class="text">(:*:)</span></code> is the product mentioned earlier, and is very similar to the <code class="codecolorer text mac-classic"><span class="text">(,)</span></code> used for constructing tuples. There are three more functors in regular: <code class="codecolorer text mac-classic"><span class="text">I</span></code>, which marks recursive positions in a type; <code class="codecolorer text mac-classic"><span class="text">(:+:)</span></code>, which sums together different constructors; and <code class="codecolorer text mac-classic"><span class="text">U</span></code>, for constructors without fields.</p>
<p>To write a generic function, we define a type class which contains this generic function, and give an instance for each of these functors. If we then also define conversion functions from our data type to the generic representation and back, we can apply the function to our data type. Note that for regular, these conversion functions, and the representation given above, can all be generated using Template Haskell.</p>
<p>Since we want to write a generic XML pickler for use with the <a href="http://hackage.haskell.org/package/hxt">HXT library</a>, we&#8217;ll define a type class containing such a pickler:</p>
<pre>
<div class="codecolorer-container haskell mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="haskell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #06c; font-weight: bold;">class</span> GXmlPickler f <span style="color: #06c; font-weight: bold;">where</span><br />
&nbsp; gxpicklef <span style="color: #339933; font-weight: bold;">::</span> PU a <span style="color: #339933; font-weight: bold;">-&gt;</span> PU <span style="color: green;">&#40;</span>f a<span style="color: green;">&#41;</span></div></div>
</pre>
<p>This says that we can give a generic pickler for one of the functors <code class="codecolorer text mac-classic"><span class="text">f</span></code>, containing <code class="codecolorer text mac-classic"><span class="text">a</span></code>&#8217;s at the recursive positions, if we have a pickler for <code class="codecolorer text mac-classic"><span class="text">a</span></code>&#8217;s. I&#8217;ll now show the instances for all the functors, and explain them one by one.</p>
<p>The first is the instance for <code class="codecolorer text mac-classic"><span class="text">I</span></code>, marking recursive positions. Since we get a pickler for the resursive positions, all we have to do is wrap it in the <code class="codecolorer text mac-classic"><span class="text">I</span></code> constructor when unpickling, and remove that constructor when pickling. HXT provides the <code class="codecolorer text mac-classic"><span class="text">xpWrap</span></code> function to transform a pickler like this.</p>
<pre>
<div class="codecolorer-container haskell mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="haskell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #06c; font-weight: bold;">instance</span> GXmlPickler I <span style="color: #06c; font-weight: bold;">where</span><br />
&nbsp; gxpicklef <span style="color: #339933; font-weight: bold;">=</span> xpWrap <span style="color: green;">&#40;</span>I<span style="color: #339933; font-weight: bold;">,</span> unI<span style="color: green;">&#41;</span></div></div>
</pre>
<p>Next, we&#8217;ll tackle <code class="codecolorer text mac-classic"><span class="text">K</span></code>. Here, we require that the type of the field has its own pickler, and use that. We again use <code class="codecolorer text mac-classic"><span class="text">xpWrap</span></code> to add and remove the constructor of the functor. We provide a special instance for <code class="codecolorer text mac-classic"><span class="text">String</span></code>, since it doesn&#8217;t have a standard pickler. We choose to use the pickler that allows empty strings.</p>
<pre>
<div class="codecolorer-container haskell mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="haskell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #06c; font-weight: bold;">instance</span> XmlPickler a <span style="color: #339933; font-weight: bold;">=&gt;</span> GXmlPickler <span style="color: green;">&#40;</span>K a<span style="color: green;">&#41;</span> <span style="color: #06c; font-weight: bold;">where</span><br />
&nbsp; gxpicklef <span style="color: #339933; font-weight: bold;">_</span> <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#40;</span>K<span style="color: #339933; font-weight: bold;">,</span> unK<span style="color: green;">&#41;</span> `xpWrap` xpickle<br />
<br />
<span style="color: #06c; font-weight: bold;">instance</span> GXmlPickler <span style="color: green;">&#40;</span>K String<span style="color: green;">&#41;</span> <span style="color: #06c; font-weight: bold;">where</span><br />
&nbsp; gxpicklef <span style="color: #339933; font-weight: bold;">_</span> <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#40;</span>K<span style="color: #339933; font-weight: bold;">,</span> unK<span style="color: green;">&#41;</span> `xpWrap` xpText0</div></div>
</pre>
<p><code class="codecolorer text mac-classic"><span class="text">U</span></code> works similarly. We use the pickler for <code class="codecolorer text mac-classic"><span class="text">()</span></code>, and use xpWrap to go from a <code class="codecolorer text mac-classic"><span class="text">()</span></code> to a <code class="codecolorer text mac-classic"><span class="text">U</span></code> and back.</p>
<pre>
<div class="codecolorer-container haskell mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="haskell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #06c; font-weight: bold;">instance</span> GXmlPickler U <span style="color: #06c; font-weight: bold;">where</span><br />
&nbsp; gxpicklef <span style="color: #339933; font-weight: bold;">_</span> <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#40;</span>const U<span style="color: #339933; font-weight: bold;">,</span> const <span style="color: green;">&#40;</span><span style="color: green;">&#41;</span><span style="color: green;">&#41;</span> `xpWrap` xpUnit</div></div>
</pre>
<p>The case for <code class="codecolorer text mac-classic"><span class="text">(:+:)</span></code> is interesting. Remember that <code class="codecolorer text mac-classic"><span class="text">(:+:)</span></code> represents a choice between two functors. If we have picklers for both of these, we can define a pickler for the sum as follows: during conversion to XML, we can pattern match on <code class="codecolorer text mac-classic"><span class="text">L</span></code> or <code class="codecolorer text mac-classic"><span class="text">R</span></code> (the constructors of <code class="codecolorer text mac-classic"><span class="text">(:+:)</span></code>) and choose the left or right pickler appropriately. During conversion from XML, we try the first pickler. If it fails (an unpickler returns a <code class="codecolorer text mac-classic"><span class="text">Maybe</span></code> value) we try the second. Since HXT doesn&#8217;t seem to have a combinator that follows this logic, let&#8217;s define one ourselves:</p>
<pre>
<div class="codecolorer-container haskell mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="haskell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">xpEither <span style="color: #339933; font-weight: bold;">::</span> PU <span style="color: green;">&#40;</span>f r<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> PU <span style="color: green;">&#40;</span>g r<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> PU <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>f :<span style="color: #339933; font-weight: bold;">+</span>: g<span style="color: green;">&#41;</span> r<span style="color: green;">&#41;</span><br />
xpEither <span style="color: green;">&#40;</span>PU fl tl sa<span style="color: green;">&#41;</span> <span style="color: green;">&#40;</span>PU fr tr sb<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> PU<br />
&nbsp; <span style="color: green;">&#40;</span>\<span style="color: green;">&#40;</span>x<span style="color: #339933; font-weight: bold;">,</span> st<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: #06c; font-weight: bold;">case</span> x <span style="color: #06c; font-weight: bold;">of</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;L y <span style="color: #339933; font-weight: bold;">-&gt;</span> fl <span style="color: green;">&#40;</span>y<span style="color: #339933; font-weight: bold;">,</span> st<span style="color: green;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;R y <span style="color: #339933; font-weight: bold;">-&gt;</span> fr <span style="color: green;">&#40;</span>y<span style="color: #339933; font-weight: bold;">,</span> st<span style="color: green;">&#41;</span><span style="color: green;">&#41;</span><br />
&nbsp; <span style="color: green;">&#40;</span>\x <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: #06c; font-weight: bold;">case</span> tl x <span style="color: #06c; font-weight: bold;">of</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: green;">&#40;</span>Nothing<span style="color: #339933; font-weight: bold;">,</span> <span style="color: #339933; font-weight: bold;">_</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> lmap <span style="color: green;">&#40;</span>fmap R<span style="color: green;">&#41;</span> <span style="color: green;">&#40;</span>tr x<span style="color: green;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;r &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #339933; font-weight: bold;">-&gt;</span> lmap <span style="color: green;">&#40;</span>fmap L<span style="color: green;">&#41;</span> r<span style="color: green;">&#41;</span><br />
&nbsp; <span style="color: green;">&#40;</span>sa `scAlt` sb<span style="color: green;">&#41;</span><br />
&nbsp; <span style="color: #06c; font-weight: bold;">where</span> lmap f <span style="color: green;">&#40;</span>a<span style="color: #339933; font-weight: bold;">,</span> b<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#40;</span>f a<span style="color: #339933; font-weight: bold;">,</span> b<span style="color: green;">&#41;</span></div></div>
</pre>
<p>Note that we take apart the <code class="codecolorer text mac-classic"><span class="text">PU</span></code> type, and create a pretty printer, a parser and a schema separately. We can use this function in the <code class="codecolorer text mac-classic"><span class="text">GXmlPickler</span></code> instance by supplying it with two picklers, created by recursive calls to <code class="codecolorer text mac-classic"><span class="text">gxpicklef</span></code>.</p>
<pre>
<div class="codecolorer-container haskell mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="haskell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #06c; font-weight: bold;">instance</span> <span style="color: green;">&#40;</span>GXmlPickler f<span style="color: #339933; font-weight: bold;">,</span> GXmlPickler g<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=&gt;</span> GXmlPickler <span style="color: green;">&#40;</span>f :<span style="color: #339933; font-weight: bold;">+</span>: g<span style="color: green;">&#41;</span> <span style="color: #06c; font-weight: bold;">where</span><br />
&nbsp; gxpicklef f <span style="color: #339933; font-weight: bold;">=</span> xpEither <span style="color: green;">&#40;</span>gxpicklef f<span style="color: green;">&#41;</span> <span style="color: green;">&#40;</span>gxpicklef f<span style="color: green;">&#41;</span></div></div>
</pre>
<p>The instance for <code class="codecolorer text mac-classic"><span class="text">(:*:)</span></code> is easy again. Since <code class="codecolorer text mac-classic"><span class="text">(:*:)</span></code> combines two functors, we can require that these two have a pickler. We use <code class="codecolorer text mac-classic"><span class="text">xpPair</span></code> to combine these into a pickler for a pair, and then use <code class="codecolorer text mac-classic"><span class="text">xpWrap</span></code> again to convert it into a pickler for <code class="codecolorer text mac-classic"><span class="text">(:*:)</span></code>.</p>
<pre>
<div class="codecolorer-container haskell mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="haskell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #06c; font-weight: bold;">instance</span> <span style="color: green;">&#40;</span>GXmlPickler f<span style="color: #339933; font-weight: bold;">,</span> GXmlPickler g<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=&gt;</span> GXmlPickler <span style="color: green;">&#40;</span>f :<span style="color: #339933; font-weight: bold;">*</span>: g<span style="color: green;">&#41;</span> <span style="color: #06c; font-weight: bold;">where</span><br />
&nbsp; gxpicklef f <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#40;</span>uncurry <span style="color: green;">&#40;</span>:<span style="color: #339933; font-weight: bold;">*</span>:<span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> \<span style="color: green;">&#40;</span>a :<span style="color: #339933; font-weight: bold;">*</span>: b<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: green;">&#40;</span>a<span style="color: #339933; font-weight: bold;">,</span> b<span style="color: green;">&#41;</span><span style="color: green;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; `xpWrap`<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: green;">&#40;</span>gxpicklef f `xpPair` gxpicklef f<span style="color: green;">&#41;</span></div></div>
</pre>
<p>Note that so far, we haven&#8217;t created any XML tags ourselves. We&#8217;ve only combined picklers. Now we come to the instances for constructors and record selectors. Here, we&#8217;ll use the constructor or selector name (converted to lowercase) to generate and parse xml tags. This is done with the <code class="codecolorer text mac-classic"><span class="text">xpElem</span></code> combinator.</p>
<pre>
<div class="codecolorer-container haskell mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="haskell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #06c; font-weight: bold;">instance</span> <span style="color: green;">&#40;</span>Constructor c<span style="color: #339933; font-weight: bold;">,</span> GXmlPickler f<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=&gt;</span> GXmlPickler <span style="color: green;">&#40;</span>C c f<span style="color: green;">&#41;</span> <span style="color: #06c; font-weight: bold;">where</span><br />
&nbsp; gxpicklef f <span style="color: #339933; font-weight: bold;">=</span> xpElem <span style="color: green;">&#40;</span>map toLower <span style="color: #339933; font-weight: bold;">$</span> conName <span style="color: green;">&#40;</span>undefined <span style="color: #339933; font-weight: bold;">::</span> C c f r<span style="color: green;">&#41;</span><span style="color: green;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>C<span style="color: #339933; font-weight: bold;">,</span> unC<span style="color: green;">&#41;</span> `xpWrap` gxpicklef f<span style="color: green;">&#41;</span><br />
<br />
<span style="color: #06c; font-weight: bold;">instance</span> <span style="color: green;">&#40;</span>Selector s<span style="color: #339933; font-weight: bold;">,</span> GXmlPickler f<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=&gt;</span> GXmlPickler <span style="color: green;">&#40;</span>S s f<span style="color: green;">&#41;</span> <span style="color: #06c; font-weight: bold;">where</span><br />
&nbsp; gxpicklef f <span style="color: #339933; font-weight: bold;">=</span> xpElem <span style="color: green;">&#40;</span>map toLower <span style="color: #339933; font-weight: bold;">$</span> selName <span style="color: green;">&#40;</span>undefined <span style="color: #339933; font-weight: bold;">::</span> S s f r<span style="color: green;">&#41;</span><span style="color: green;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>S<span style="color: #339933; font-weight: bold;">,</span> unS<span style="color: green;">&#41;</span> `xpWrap` gxpicklef f<span style="color: green;">&#41;</span></div></div>
</pre>
<p>We now have picklers for all generic representations built from the standard functors in regular. We still need a top level function that works on our real data types, though. Regular provides the two functions <code class="codecolorer text mac-classic"><span class="text">to</span></code> and <code class="codecolorer text mac-classic"><span class="text">from</span></code> to convert between data types and their generic representation. We can use these together with <code class="codecolorer text mac-classic"><span class="text">xpWrap</span></code> to change our generic pickler into a pickler for real data types. Another matter we have not addressed is the first argument to <code class="codecolorer text mac-classic"><span class="text">gpicklef</span></code>, which is a pickler for the recursive positions. Here we pass the top level function, since the recursive position contains our original data type again.</p>
<pre>
<div class="codecolorer-container haskell mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="haskell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">gxpickle <span style="color: #339933; font-weight: bold;">::</span> <span style="color: green;">&#40;</span>Regular a<span style="color: #339933; font-weight: bold;">,</span> GXmlPickler <span style="color: green;">&#40;</span>PF a<span style="color: green;">&#41;</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=&gt;</span> PU a<br />
gxpickle <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#40;</span>to<span style="color: #339933; font-weight: bold;">,</span> from<span style="color: green;">&#41;</span> `xpWrap` gxpicklef gxpickle</div></div>
</pre>
<p>And that&#8217;s all for the generic XML pickler. Using it is very simple. To use it for our user data type above, we import <code class="codecolorer text mac-classic"><span class="text">Generic.Regular</span></code>, <code class="codecolorer text mac-classic"><span class="text">Generic.Regular.TH</span></code>, <code class="codecolorer text mac-classic"><span class="text">Generic.Regular.XmlPickler</span></code> and <code class="codecolorer text mac-classic"><span class="text">Text.XML.HXT.Arrow.Pickle</span></code>. We can then derive the <code class="codecolorer text mac-classic"><span class="text">Regular</span></code> instance for user (note that we need a little bit of extra code, since Template Haskell cannot generate type family instances yet), and make an <code class="codecolorer text mac-classic"><span class="text">XmlPickler</span></code> instance:</p>
<pre>
<div class="codecolorer-container haskell mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="haskell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933; font-weight: bold;">$</span><span style="color: green;">&#40;</span>deriveAll ''User <span style="background-color: #3cb371;">&quot;PFUser&quot;</span><span style="color: green;">&#41;</span><br />
<span style="color: #06c; font-weight: bold;">type</span> <span style="color: #06c; font-weight: bold;">instance</span> PF User <span style="color: #339933; font-weight: bold;">=</span> PFUser<br />
<br />
<span style="color: #06c; font-weight: bold;">instance</span> XmlPickler User <span style="color: #06c; font-weight: bold;">where</span><br />
&nbsp; xpickle <span style="color: #339933; font-weight: bold;">=</span> gxpickle</div></div>
</pre>
<p>And that&#8217;s it! The package is available as <a href="http://hackage.haskell.org/package/regular-xmlpickler">regular-xmlpickler</a> on hackage, and the source can also be found on <a href="http://github.com/typLAB/regular-xmlpickler">github</a>. The packages <a href="http://hackage.haskell.org/package/regular">regular</a> and <a href="http://hackage.haskell.org/package/hxt">HXT</a> can also be found on hackage.</p>
<img src="http://feeds.feedburner.com/~r/typlab/blog/~4/FB7iN7BZQOo" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.typlab.com/2009/11/writing-a-generic-xml-pickler/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		<feedburner:origLink>http://blog.typlab.com/2009/11/writing-a-generic-xml-pickler/</feedburner:origLink></item>
		<item>
		<title>How I Learned to Stop Worrying and Love Web Development Again</title>
		<link>http://feedproxy.google.com/~r/typlab/blog/~3/YBeIxV5eL7A/</link>
		<comments>http://blog.typlab.com/2009/10/love-web-development-again/#comments</comments>
		<pubDate>Wed, 28 Oct 2009 07:42:23 +0000</pubDate>
		<dc:creator>Salar</dc:creator>
				<category><![CDATA[Company]]></category>

		<guid isPermaLink="false">http://blog.typlab.com/?p=152</guid>
		<description><![CDATA[Why we don&#8217;t support Internet Explorer
We&#8217;ve already talked about some of the technology choices we&#8217;re making as a company. And while our choices on the back-end can hardly be labeled as mainstream, the most difficult choice we actually had to make was related to the client-side as it directly affects our users. Obviously, Javascript on [...]]]></description>
			<content:encoded><![CDATA[<h2>Why we don&#8217;t support Internet Explorer</h2>
<p>We&#8217;ve already talked about some of the technology choices we&#8217;re making as a company. And while our <a title="Haskell data types and XML" href="/2009/09/haskell-data-types-and-xml/">choices</a> on the back-end can hardly be labeled as <a title="Why we use Haskell" href="/2009/09/why-we-use-haskell/">mainstream</a>, the most difficult choice we actually had to make was related to the client-side as it directly affects our users. Obviously, Javascript on the client is a given, and we love it. However, as most web developers know, the differences between browsers are enormous and developing for all of them is almost impossible<sup>1</sup>. Still, current conventional wisdom dictates that you should support recents versions of Internet Explorer<sup>2</sup>, Firefox and the WebKit based browsers (basically, Safari and Google Chrome). We, however, have decided to drop Internet Explorer support entirely<sup>3</sup>.</p>
<p><span id="more-152"></span><br />
In general, the trade-off you face when choosing which platform to develop for is between development time and a larger potential customer base that&#8217;s associated with the platform. Looking at the web right now, Internet Explorer still leads the market by a large margin<sup>4</sup>. So even if it seems annoying that you have to work around some CSS bugs or still write Internet Explorer specific event handling code for a web site, the payoff in user reach will usually still be worth it. Modern Javascript libraries such as <a href="http://jquery.com/">jQuery</a> or <a href="http://mootools.net/">Mootools</a> lower cross-browser development time even more by abstracting away lots of differences between browsers, tipping the equation even more in favor of Internet Explorer support.</p>
<p>So why did we choose to ignore the most used browser on the planet? It&#8217;s because we decided that in our case, the development costs would simply not be worth it. Obviously, this assessment is very specific for the type of application we&#8217;re building. We didn&#8217;t just base this on a hunch, we actually have quite some experience in this field: most of us have worked on products like <a href="http://xopus.com">Xopus</a> before. Xopus is an awesome, browser based wysiwyg XML editor. It consist of more than <a href="http://www.slideshare.net/ajaxexperience2009/laurens-van-den-oever-xopus-presentation">120,000 lines of client-side Javascript code</a>. A non-trivial part of that is code that completely works around standard Internet Explorer behavior because of its bugginess or complete lack of support. This isn&#8217;t about your father&#8217;s unsupported CSS selectors or the lack of addEventListener. We&#8217;re talking about stuff like <a href="http://xopus.com/devblog/2007/craziest-dhtml-hack-ever.html">having to write your own cursor</a> because <tt>contentEditable</tt> becomes basically useless when working on complex documents. The amount of bugs that are related to <tt>contentEditable</tt>, text ranges, drag and drop and the Document Object Model in general are staggering. Most JavaScript projects, including some popular libraries, don&#8217;t even deal with these advanced aspects of the browser at all.</p>
<p>Now obviously, the other browsers aren&#8217;t all free of bugs. Which brings us to the second problem with Internet Explorer: lack of real progress and transparency. Even if you consider relatively easy and popular features (such as support for <tt>addEventListener</tt>), it&#8217;s hard to understand why they haven&#8217;t been implemented yet and if there is any timeline at all to implement them. That makes the probability of low visibility improvements and bug fixes in the rendering or selection code practically zero. The contrast with the open development of Mozilla and WebKit is huge, where almost everything is publicly discussed and with a focus on constant improvement of the rendering engines and pretty clear timeline.</p>
<p>The current state of the web is actually very exciting right now, if we ignore Internet Explorer for a moment. Thanks to HTML5 there is a lot of progress allowing us to make almost desktop class applications, with support for things like <a href="http://www.alertdebugging.com/2009/08/16/on-html-5-drag-and-drop/">drag and drop from the desktop</a>, <a href="https://developer.mozilla.org/En/Using_web_workers">background processes</a> and <a href="http://developer.apple.com/safari/library/documentation/iPhone/Conceptual/SafariJSDatabaseGuide/OfflineApplicationCache/OfflineApplicationCache.html">offline support</a><sup>5</sup>. All of this should greatly improve the user experience with web applications and bridge the gap with desktop applications. No amount of code or smart engineering will allow us to bring that level of experience to browsers that lack these features.</p>
<p>Does this mean that no complex web application should support Internet Explorer? Obviously, it depends on many factors. There are large differences between applications that are targeted to tech-savvy users (where Internet Explorer is quickly becoming a minority browser) or to large organizations (where Internet Explorer 6 is still widely used). We&#8217;re a small team and we have to prioritize our development goals aggressively. Large teams with lots of resources are in a different situation altogether. That being said, we were pleased to see that the Google Wave team also chose to <a href="http://googlewavedev.blogspot.com/2009/09/google-wave-in-internet-explorer.html">drop Internet Explorer support</a> and having Google develope the <a href="http://code.google.com/chrome/chromeframe/">Chrome Frame plug-in</a>.</p>
<p>Finally, although this might seem less important than the above considerations from a business perspective, there is the loss of friction and return of enjoyment in developing web applications again. Not developing for Internet Explorer means that we can do amazing things with <a href="http://webkit.org/blog/138/css-animation/">CSS</a>, use <a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Guide/Creating_New_Objects/Defining_Getters_and_Setters">new Javascript features</a> in our codebase, and in general rediscover the excitement of the possibilities of the web. And that makes us love web development again.</p>
<ol class="footnotes"><li id="footnote_0_152" class="footnote">Try using Netscape 4.7 today, if you&#8217;re curious.</li><li id="footnote_1_152" class="footnote">Usually, this means Internet Explorer 6 and newer. However support for Internet Explorer 6 is slowly declining, as it&#8217;s dropped by major sites like <a href="http://www.google.com/support/youtube/bin/answer.py?hl=en&amp;answer=157259">YouTube</a>, <a href="http://arstechnica.com/microsoft/news/2009/08/googles-orkut-starts-phasing-out-support-for-ie6.ars">Orkut</a> and products like <a href="http://productblog.37signals.com/products/2008/07/basecamp-phasin.html">Basecamp</a>.</li><li id="footnote_2_152" class="footnote">Note that what we&#8217;re discussing here is browser support for our <em>application</em>. The content that resides inside the application will always be available to any web browser, whether it&#8217;s a text-based browser with no Javascript support, a low capability mobile browser or Internet Explorer 6. This is based on the principe of <a href="http://dev.opera.com/articles/view/graceful-degradation-progressive-enhance/#gracefulprogressivenutshell">graceful degradation</a>.</li><li id="footnote_3_152" class="footnote">Wikipedia has a <a href="http://en.wikipedia.org/wiki/Usage_share_of_web_browsers#Summary_Table">nice summary of various sources</a> with browser usage statisics.</li><li id="footnote_4_152" class="footnote">To be fair, Internet Explorer 8 does provide some offline support.</li></ol><img src="http://feeds.feedburner.com/~r/typlab/blog/~4/YBeIxV5eL7A" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.typlab.com/2009/10/love-web-development-again/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		<feedburner:origLink>http://blog.typlab.com/2009/10/love-web-development-again/</feedburner:origLink></item>
		<item>
		<title>Mutation Events: What Happen?</title>
		<link>http://feedproxy.google.com/~r/typlab/blog/~3/3FLsCCWD6rs/</link>
		<comments>http://blog.typlab.com/2009/10/mutation-events-what-happen/#comments</comments>
		<pubDate>Thu, 08 Oct 2009 13:16:56 +0000</pubDate>
		<dc:creator>Lon</dc:creator>
				<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://blog.typlab.com/?p=120</guid>
		<description><![CDATA[Since typLAB is all about exploring new ways of creating and consuming online content we figured our software might want to keep track of what&#8217;s happening inside a document.
All modern browsers have support for W3C&#8217;s mutation events. Safari, Chrome, FireFox and Opera all do them. But not all do all of them.
Notably WebKit fails to fire DOMAttrModified [...]]]></description>
			<content:encoded><![CDATA[<p>Since typ<span class="lab">LAB</span> is all about exploring new ways of creating and consuming online content we figured our software might want to keep track of what&#8217;s happening inside a document.</p>
<p>All modern browsers have support for <a href="http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-eventgroupings-mutationevents">W3C&#8217;s mutation events</a>. Safari, Chrome, FireFox and Opera all do them. But not all do all of them.</p>
<p>Notably <a href="https://bugs.webkit.org/show_bug.cgi?id=8191">WebKit fails to fire <tt>DOMAttrModified</tt></a> events when an attribute is changed. It does however fire the <code class="codecolorer text mac-classic"><span class="text">DOMSubtreeModified</span></code> event after an attribute is modified. So at least that gives us something to work with until the good folks at WebKit squash the bug.</p>
<p><span id="more-120"></span></p>
<p>Here is how we fixed the lack of <code class="codecolorer text mac-classic"><span class="text">DOMAttrModified</span></code>. First we need to detect whether the fix is needed:</p>
<pre>
<div class="codecolorer-container javascript mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">var</span> attrModifiedWorks <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
<span style="color: #003366; font-weight: bold;">var</span> listener <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> attrModifiedWorks <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
document.<span style="color: #660066;">documentElement</span>.<span style="color: #660066;">addEventListener</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;DOMAttrModified&quot;</span><span style="color: #339933;">,</span> listener<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
document.<span style="color: #660066;">documentElement</span>.<span style="color: #660066;">setAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;___TEST___&quot;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
document.<span style="color: #660066;">documentElement</span>.<span style="color: #660066;">removeAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;___TEST___&quot;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
document.<span style="color: #660066;">documentElement</span>.<span style="color: #660066;">removeEventListener</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;DOMAttrModified&quot;</span><span style="color: #339933;">,</span> listener<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
</pre>
<p>The code is straightforward. Add an attribute and have a listener register the firing of the subsequent <code class="codecolorer text mac-classic"><span class="text">DOMAttrModified</span></code> event. If the event is not fired our repair code kicks in:</p>
<pre>
<div class="codecolorer-container javascript mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>attrModifiedWorks<span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span></div></div>
</pre>
<p>Next we store and override <code class="codecolorer text mac-classic"><span class="text">HTMLElement.setAttribute</span></code>:</p>
<pre>
<div class="codecolorer-container javascript mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">HTMLElement.<span style="color: #660066;">prototype</span>.__setAttribute <span style="color: #339933;">=</span> HTMLElement.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">setAttribute</span><br />
<br />
HTMLElement.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">setAttribute</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>attrName<span style="color: #339933;">,</span> newVal<span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #003366; font-weight: bold;">var</span> prevVal <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">getAttribute</span><span style="color: #009900;">&#40;</span>attrName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #000066; font-weight: bold;">this</span>.__setAttribute<span style="color: #009900;">&#40;</span>attrName<span style="color: #339933;">,</span> newVal<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; newVal <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">getAttribute</span><span style="color: #009900;">&#40;</span>attrName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>newVal <span style="color: #339933;">!=</span> prevVal<span style="color: #009900;">&#41;</span><br />
&nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> evt <span style="color: #339933;">=</span> document.<span style="color: #660066;">createEvent</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;MutationEvent&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; evt.<span style="color: #660066;">initMutationEvent</span><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;DOMAttrModified&quot;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; prevVal <span style="color: #339933;">||</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; newVal <span style="color: #339933;">||</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; attrName<span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#40;</span>prevVal <span style="color: #339933;">==</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> evt.<span style="color: #660066;">ADDITION</span> <span style="color: #339933;">:</span> evt.<span style="color: #660066;">MODIFICATION</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">dispatchEvent</span><span style="color: #009900;">&#40;</span>evt<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
</pre>
<p>The new code fetches the current value of the attribute, soon to become the previous value.<br />
It then proceeds to set the attribute using the original <code class="codecolorer text mac-classic"><span class="text">setAttribute</span></code> method that we stored.<br />
We don&#8217;t know whether that method does fancy stuff to the new attribute value, so, just to be sure, we fetch the new value by calling <code class="codecolorer text mac-classic"><span class="text">getAttribute</span></code> once again.<br />
If and only if the new and previous value differ we proceed to dispatch the appropriately initialised mutation event.</p>
<p>This covers added and modified attributes. But it won&#8217;t help us with removed attributes. For those we can override the <code class="codecolorer text mac-classic"><span class="text">removeAttribute</span></code> method of <code class="codecolorer text mac-classic"><span class="text">HTMLElement</span></code>:</p>
<pre>
<div class="codecolorer-container javascript mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">HTMLElement.<span style="color: #660066;">prototype</span>.__removeAttribute <span style="color: #339933;">=</span> HTMLElement.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">removeAttribute</span><span style="color: #339933;">;</span><br />
HTMLElement.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">removeAttribute</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>attrName<span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #003366; font-weight: bold;">var</span> prevVal <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">getAttribute</span><span style="color: #009900;">&#40;</span>attrName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #000066; font-weight: bold;">this</span>.__removeAttribute<span style="color: #009900;">&#40;</span>attrName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #003366; font-weight: bold;">var</span> evt <span style="color: #339933;">=</span> document.<span style="color: #660066;">createEvent</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;MutationEvent&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; evt.<span style="color: #660066;">initMutationEvent</span><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; <span style="color: #3366CC;">&quot;DOMAttrModified&quot;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; prevVal<span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; attrName<span style="color: #339933;">,</span><br />
&nbsp; &nbsp; evt.<span style="color: #660066;">REMOVAL</span><br />
&nbsp; <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">dispatchEvent</span><span style="color: #009900;">&#40;</span>evt<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
</pre>
<p>This concludes our fix for the lack of <code class="codecolorer text mac-classic"><span class="text">DOMAttrModified</span></code> in WebKit.<br />
Is this fix perfect? Nope. Some known issues:</p>
<ul>
<li>a <code class="codecolorer text mac-classic"><span class="text">DOMSubtreeModified</span></code> event is fired before instead of after the (artificial) <code class="codecolorer text mac-classic"><span class="text">DOMAttrModified</span></code> event</li>
<li>assigning a value to an attribute will not trigger our <code class="codecolorer text mac-classic"><span class="text">setAttribute</span></code> method. Most noticeably assigning a value to a <code class="codecolorer text mac-classic"><span class="text">className</span></code> or <code class="codecolorer text mac-classic"><span class="text">id</span></code> attribute will not result in the appropriate <code class="codecolorer text mac-classic"><span class="text">DOMAttrModified</span></code> event</li>
</ul>
<p>We&#8217;re open for suggestions. But best would be if some WebKit developer would fix <a href="https://bugs.webkit.org/show_bug.cgi?id=8191">the bug</a> so we can throw this code away.</p>
<img src="http://feeds.feedburner.com/~r/typlab/blog/~4/3FLsCCWD6rs" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.typlab.com/2009/10/mutation-events-what-happen/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://blog.typlab.com/2009/10/mutation-events-what-happen/</feedburner:origLink></item>
		<item>
		<title>Haskell data types and XML</title>
		<link>http://feedproxy.google.com/~r/typlab/blog/~3/fjQaOfSdwpc/</link>
		<comments>http://blog.typlab.com/2009/09/haskell-data-types-and-xml/#comments</comments>
		<pubDate>Thu, 24 Sep 2009 06:42:28 +0000</pubDate>
		<dc:creator>Sebas</dc:creator>
				<category><![CDATA[Haskell]]></category>

		<guid isPermaLink="false">http://blog.typlab.com/?p=15</guid>
		<description><![CDATA[Here at typLAB it wasn&#8217;t evident from the beginning what would be the best choice for a storage back-end. We knew that we were about to build a web based editor and would be dealing with a lot of HTML5 documents with lots of meta data. After some careful consideration we decided to go for [...]]]></description>
			<content:encoded><![CDATA[<p>Here at typ<span class="lab">LAB</span> it wasn&#8217;t evident from the beginning what would be the best choice for a storage back-end. We knew that we were about to build a web based editor and would be dealing with a lot of <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/">HTML5</a> documents with lots of meta data. After some careful consideration we decided to go for an XML database. More specifically, the <a href="http://www.oracle.com/database/berkeley-db/xml/index.html">Berkeley XML Database</a>, lovingly called DBXML by its authors.</p>
<p>We figured that using DBXML would give us some important advantages:</p>
<ul>
<li>Collections of HTML5 documents will form the basis of data model. Only one trivial conversion from HTML5 to syntactically valid XML is needed to get our documents into the XML database. Once stored we can perform some interesting queries over our data.</li>
<li>XML databases allow for the storage of complex data layouts without having a strict schema. Without a schema it will be easier to adjust our data model over time without instantly breaking our software.</li>
<li><a href="http://www.w3.org/TR/xquery/">XQuery</a> is a very expressive (almost-purely functional) querying language which is at least as powerful as SQL and far more flexible in the structure of the data to target.</li>
<li>XML can be used to both encode strictly defined datatypes and store free-form documents in the same document collection. This will enable us to put both our meta data and our documents in the same database.</li>
<li>A quick look on Hackage revealed there is an out-of-the-box easy-to-use <a href="http://hackage.haskell.org/package/BerkeleyDBXML">Haskell binding</a> available for the Berkeley XML database. No need to create custom bindings ourselves.</li>
<li>We are in the advantage (or disadvantage) of having Haskell as our language of choice for our server software. Because of the hierarchical nature of both XML and Haskell algebraic datatypes, an XML database feels like a perfect fit.</li>
</ul>
<p>Once we decided to go for an DBXML back-end we had to figure out how to easily get values form our Haskell program in and out of the database. The rest of this post will be dealing with the last point of our enumeration: how to get a nice mapping from Haskell&#8217;s algebraic datatypes to our DBXML back-end.</p>
<p><span id="more-15"></span></p>
<h2>XML queries</h2>
<p>The DBXML binding for Haskell is a shallow wrapper around the existing C++ API. This library allows us to perform the common create, read, update and delete queries for entire XML documents or parts of it. Communication with the XML database happens mainly via XQuery. Queries and query parameters are passed into the API (and results will come out) using Haskell <a href="http://hackage.haskell.org/packages/archive/bytestring/0.9.1.4/doc/html/Data-ByteString.html#1"><code class="codecolorer text mac-classic"><span class="text">ByteString</span></code></a>s. It is up to the programmer to setup the queries with the right XML structure and encoding. Take for example the (somewhat simplified) type signature of the <code class="codecolorer text mac-classic"><span class="text">query</span></code> function:</p>
<pre>
<div class="codecolorer-container haskell mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="haskell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">query <span style="color: #339933; font-weight: bold;">::</span> Collection <span style="color: #339933; font-weight: bold;">-&gt;</span> Query <span style="color: #339933; font-weight: bold;">-&gt;</span> Parameters <span style="color: #339933; font-weight: bold;">-&gt;</span> IO <span style="color: green;">&#91;</span>ByteString<span style="color: green;">&#93;</span></div></div>
</pre>
<p>This function takes an identification of the XML collection, which is somewhat like a database handle, an XML query, a set of query parameters and returns a possibly empty list of XML snippets as <code class="codecolorer text mac-classic"><span class="text">ByteString</span></code>s. Too bad that all our domain objects are well-typed Haskell algebraic datatypes and not raw sequences of bytes. We need a simple XML (de)serialization tool for this.</p>
<h2>XML picklers</h2>
<p>The <a href="http://hackage.haskell.org/package/hxt">Haskell XML Toolbox</a> (HXT) is a library containing a (quite extended) collection of XML processing tools. The library has support for XML parsing, pretty printing, XPath queries, XSL stylesheets, DTD, XSD and RelaxNG schemas and a lot more. Interestingly, HXT exposes a type class and an accompanying set of combinators called XML picklers. XML picklers can be used to build conversion functions from Haskell datatypes to XML and vice versa. The type class looks like this:</p>
<pre>
<div class="codecolorer-container haskell mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="haskell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; <span style="color: #06c; font-weight: bold;">class</span> XmlPickler a <span style="color: #06c; font-weight: bold;">where</span><br />
&nbsp; &nbsp; xpickle <span style="color: #339933; font-weight: bold;">::</span> PU a</div></div>
</pre>
<p>So for every type in the <a href="http://hackage.haskell.org/packages/archive/hxt/8.3.1/doc/html/Text-XML-HXT-Arrow-Pickle.html#t%3AXmlPickler"><code class="codecolorer text mac-classic"><span class="text">XmlPickler</span></code></a> type class there is some <a href="http://hackage.haskell.org/packages/archive/hxt/8.3.1/doc/html/Text-XML-HXT-Arrow-Pickle.html#t%3APU"><code class="codecolorer text mac-classic"><span class="text">PU</span></code></a> available. The <code class="codecolorer text mac-classic"><span class="text">PU</span></code> datatype is composed of a pair of pickle (serialize) and unpickle (deserialize) functions together with a schema description. Because we won&#8217;t be using the schema definitions we will ignore them for now. There is probably no need to ever touch the functions inside the <code class="codecolorer text mac-classic"><span class="text">PU</span></code> type, because the library supplies a vast amount of basic pickler combinators to be used instead.</p>
<p>To illustrate the usage of HXT picklers take this simple Haskell datatype representing a single user in our system:</p>
<pre>
<div class="codecolorer-container haskell mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="haskell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #06c; font-weight: bold;">data</span> User <span style="color: #339933; font-weight: bold;">=</span> User<br />
&nbsp; <span style="color: green;">&#123;</span> name &nbsp; &nbsp; <span style="color: #339933; font-weight: bold;">::</span> String<br />
&nbsp; <span style="color: #339933; font-weight: bold;">,</span> email &nbsp; &nbsp;<span style="color: #339933; font-weight: bold;">::</span> String<br />
&nbsp; <span style="color: #339933; font-weight: bold;">,</span> password <span style="color: #339933; font-weight: bold;">::</span> String<br />
&nbsp; <span style="color: #339933; font-weight: bold;">,</span> openID &nbsp; <span style="color: #339933; font-weight: bold;">::</span> String<br />
&nbsp; <span style="color: green;">&#125;</span></div></div>
</pre>
<p>Using some of the basic pickler combinators from the library it is very easy to come up with a suitable <code class="codecolorer text mac-classic"><span class="text">XmlPickler</span></code> instance:</p>
<pre>
<div class="codecolorer-container haskell mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="haskell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #06c; font-weight: bold;">class</span> XmlPickler User <span style="color: #06c; font-weight: bold;">where</span><br />
&nbsp; userPickle <span style="color: #339933; font-weight: bold;">=</span><br />
&nbsp; &nbsp; xpElem <span style="background-color: #3cb371;">&quot;user&quot;</span><br />
&nbsp; &nbsp; <span style="color: #339933; font-weight: bold;">$</span> xpWrap<br />
&nbsp; &nbsp; &nbsp; <span style="color: green;">&#40;</span> <span style="color: green;">&#40;</span>\<span style="color: green;">&#40;</span>a<span style="color: #339933; font-weight: bold;">,</span> b<span style="color: #339933; font-weight: bold;">,</span> c<span style="color: #339933; font-weight: bold;">,</span> d<span style="color: #339933; font-weight: bold;">,</span> e<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> User a b c d e<span style="color: green;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span>\<span style="color: green;">&#40;</span>User a b c d e<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: green;">&#40;</span>a<span style="color: #339933; font-weight: bold;">,</span> b<span style="color: #339933; font-weight: bold;">,</span> c<span style="color: #339933; font-weight: bold;">,</span> d<span style="color: #339933; font-weight: bold;">,</span> e<span style="color: green;">&#41;</span><span style="color: green;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: green;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #339933; font-weight: bold;">$</span> xp5Tuple<br />
&nbsp; &nbsp; &nbsp; <span style="color: green;">&#40;</span>xpElem <span style="background-color: #3cb371;">&quot;username&quot;</span> xpText<span style="color: green;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: green;">&#40;</span>xpElem <span style="background-color: #3cb371;">&quot;name&quot;</span> &nbsp; &nbsp; xpText<span style="color: green;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: green;">&#40;</span>xpElem <span style="background-color: #3cb371;">&quot;password&quot;</span> xpText<span style="color: green;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: green;">&#40;</span>xpElem <span style="background-color: #3cb371;">&quot;email&quot;</span> &nbsp; &nbsp;xpText<span style="color: green;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: green;">&#40;</span>xpElem <span style="background-color: #3cb371;">&quot;openid&quot;</span> &nbsp; xpText0<span style="color: green;">&#41;</span></div></div>
</pre>
<p>This instance uses the <a href="http://hackage.haskell.org/packages/archive/hxt/8.3.1/doc/html/Text-XML-HXT-Arrow-Pickle.html#v%3Axp5Tuple"><code class="codecolorer text mac-classic"><span class="text">xp5Tuple</span></code></a> function to pickle five sub-picklers into a big tuple. The five fields will be appropriately named elements from which the text value will be used. The tuple will be converted into a value of the <code class="codecolorer text mac-classic"><span class="text">User</span></code> datatype using the <a href="http://hackage.haskell.org/packages/archive/hxt/8.3.1/doc/html/Text-XML-HXT-Arrow-Pickle.html#v%3AxpWrap"><code class="codecolorer text mac-classic"><span class="text">xpWrap</span></code></a> function. This is all you to need to manually write XML serialization and deserialization code.</p>
<p>A bit off topic but interesting to note is the fact that the <code class="codecolorer text mac-classic"><span class="text">xpWrap</span></code> function can be seen as a pickler specific and bidirectional version of the well known <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:fmap"><code class="codecolorer text mac-classic"><span class="text">fmap</span></code></a> for <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#t%3AFunctor"><code class="codecolorer text mac-classic"><span class="text">Functor</span></code></a>s. The <code class="codecolorer text mac-classic"><span class="text">xpWrap</span></code> is used to define true isomorphisms. When we generalize the type of <code class="codecolorer text mac-classic"><span class="text">xpWrap</span></code> to work arbitrary containers, lets call this function <code class="codecolorer text mac-classic"><span class="text">bifmap</span></code>, and compare the type signatures this similarity becomes obvious:</p>
<pre>
<div class="codecolorer-container haskell mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="haskell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">fmap &nbsp; <span style="color: #339933; font-weight: bold;">::</span> <span style="color: green;">&#40;</span>a <span style="color: #339933; font-weight: bold;">-&gt;</span> b<span style="color: green;">&#41;</span> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933; font-weight: bold;">-&gt;</span> f a <span style="color: #339933; font-weight: bold;">-&gt;</span> f b<br />
bifmap <span style="color: #339933; font-weight: bold;">::</span> <span style="color: green;">&#40;</span>a <span style="color: #339933; font-weight: bold;">-&gt;</span> b<span style="color: #339933; font-weight: bold;">,</span> b <span style="color: #339933; font-weight: bold;">-&gt;</span> a<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> f a <span style="color: #339933; font-weight: bold;">-&gt;</span> f b</div></div>
</pre>
<p>So, taking the <code class="codecolorer text mac-classic"><span class="text">XmlPickler</span></code> instance for our <code class="codecolorer text mac-classic"><span class="text">User</span></code> datatype we can now easily convert users into XML and read them back in, like the following example:</p>
<pre>
<div class="codecolorer-container haskell mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="haskell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">User <span style="background-color: #3cb371;">&quot;jd&quot;</span> <span style="background-color: #3cb371;">&quot;John Doe&quot;</span> <span style="background-color: #3cb371;">&quot;secret&quot;</span> <span style="background-color: #3cb371;">&quot;john@doe&quot;</span> <span style="background-color: #3cb371;">&quot;none&quot;</span></div></div>
</pre>
<pre>
<div class="codecolorer-container xml mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;user<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;username<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>jd<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/username<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>John Doe<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;password<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>secret<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/password<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;email<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>john@doe<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/email<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;openid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>none<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/openid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/user<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></div>
</pre>
<p>Using the <a href="http://hackage.haskell.org/packages/archive/hxt/8.3.1/doc/html/Text-XML-HXT-Arrow-Pickle.html#t%3AXmlPickler"><code class="codecolorer text mac-classic"><span class="text">xpickle</span></code></a> function from the type class and the <a href="http://hackage.haskell.org/packages/archive/hxt/8.3.1/doc/html/Text-XML-HXT-Arrow-Pickle.html#v%3AxunpickleVal"><code class="codecolorer text mac-classic"><span class="text">xunpickleVal</span></code></a> from the HXT library we can now write a more suitable query function on top of the raw version. This version does not return <code class="codecolorer text mac-classic"><span class="text">ByteString</span></code>s, but values of any type we can convert to. Off course, the information in the database should match your datatype, otherwise the unpickler function will just produce parse errors resulting in an empty list.</p>
<pre>
<div class="codecolorer-container haskell mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="haskell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">query <span style="color: #339933; font-weight: bold;">::</span> XmlPickler a <span style="color: #339933; font-weight: bold;">=&gt;</span> Collection <span style="color: #339933; font-weight: bold;">-&gt;</span> Query <span style="color: #339933; font-weight: bold;">-&gt;</span> Parameters <span style="color: #339933; font-weight: bold;">-&gt;</span> IO <span style="color: green;">&#91;</span>a<span style="color: green;">&#93;</span></div></div>
</pre>
<p>Although this pickler example for our user is a very simple one, even more complicated datatypes, including multi-constructor and possibly mutual recursive datatypes, can quite easily be made an instance of the <code class="codecolorer text mac-classic"><span class="text">XmlPickler</span></code> class. Unfortunately we still have to write them all by hand.</p>
<h2>Going generic</h2>
<p>After a few of years at the University of Utrecht we learned at least one valuable lesson, never write functions by hand when they can be <a href="http://www.cs.uu.nl/wiki/GenericProgramming">derived generically</a>. We decided to write a generic XML pickler function using the generic programming library <a href="http://hackage.haskell.org/package/regular">Regular</a>, developed (not entirely coincidentally) at the University of Utrecht. Regular is a relatively simple but powerful tool for writing data type generic functions. The library has support for deriving embedding projection pairs (conversions from and to a generic representation) using <a href="http://www.haskell.org/th/">Template Haskell</a> and provides enough reflection to inspect constructor names and record labels.</p>
<p>The generic representation is encoded as a type family (the pattern functor, or <code class="codecolorer text mac-classic"><span class="text">PF</span></code>) over the original data type. The generic pickler function we developed has the following signature:</p>
<pre>
<div class="codecolorer-container haskell mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="haskell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">gxpickle <span style="color: #339933; font-weight: bold;">::</span> <span style="color: green;">&#40;</span>Regular a<span style="color: #339933; font-weight: bold;">,</span> GXmlPickler <span style="color: green;">&#40;</span>PF a<span style="color: green;">&#41;</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=&gt;</span> PU a</div></div>
</pre>
<p>This means that for every type that we can convert to a generic representation (indicated by the <code class="codecolorer text mac-classic"><span class="text">Regular</span></code> type class) and for every type that has a <code class="codecolorer text mac-classic"><span class="text">GXmlPickler</span></code> instance for its generic representation, we can deliver a <code class="codecolorer text mac-classic"><span class="text">PU</span></code>. The <code class="codecolorer text mac-classic"><span class="text">regular-xmlpickler</span></code> package implements the <code class="codecolorer text mac-classic"><span class="text">GXmlPickler</span></code> type class and the instances for the types of which the representations are composed. So, all we need now for our <code class="codecolorer text mac-classic"><span class="text">User</span></code> datatype is to derive a generic representation and use the generic implementation for the <code class="codecolorer text mac-classic"><span class="text">XmlPickler</span></code> instance.</p>
<pre>
<div class="codecolorer-container haskell mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="haskell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933; font-weight: bold;">$</span><span style="color: green;">&#40;</span>deriveAll ''User <span style="background-color: #3cb371;">&quot;PFUser&quot;</span><span style="color: green;">&#41;</span><br />
<span style="color: #06c; font-weight: bold;">type</span> <span style="color: #06c; font-weight: bold;">instance</span> PF User <span style="color: #339933; font-weight: bold;">=</span> PFUser<br />
<br />
<span style="color: #06c; font-weight: bold;">instance</span> XmlPickler User <span style="color: #06c; font-weight: bold;">where</span><br />
&nbsp; xpickle <span style="color: #339933; font-weight: bold;">=</span> gxpickle</div></div>
</pre>
<p>Using this automatically derived XML pickler and the query function described above we can now query the DBXML backend for all users that satisfy a certain property:</p>
<pre>
<div class="codecolorer-container haskell mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="haskell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">jd <span style="color: #339933; font-weight: bold;">::</span> IO <span style="color: green;">&#91;</span>User<span style="color: green;">&#93;</span><br />
jd <span style="color: #339933; font-weight: bold;">=</span> query myCollection <span style="background-color: #3cb371;">&quot;/user[username=$name]&quot;</span> <span style="color: green;">&#91;</span><span style="color: green;">&#40;</span><span style="background-color: #3cb371;">&quot;name&quot;</span><span style="color: #339933; font-weight: bold;">,</span> <span style="background-color: #3cb371;">&quot;jd&quot;</span><span style="color: green;">&#41;</span><span style="color: green;">&#93;</span></div></div>
</pre>
<p>Now we&#8217;re able to query a database for pieces of XML and reify these as true Haskell values with almost no boilerplate involved! Because of the bidirectional behavior of the <code class="codecolorer text mac-classic"><span class="text">XmlPickler</span></code> type class it shouldn&#8217;t be difficult to imagine that the same trick is applicable to inserting and updating database entries.</p>
<p>We will discuss writing generic functions using the Regular library in a later post.</p>
<img src="http://feeds.feedburner.com/~r/typlab/blog/~4/fjQaOfSdwpc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.typlab.com/2009/09/haskell-data-types-and-xml/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		<feedburner:origLink>http://blog.typlab.com/2009/09/haskell-data-types-and-xml/</feedburner:origLink></item>
		<item>
		<title>Why we use Haskell</title>
		<link>http://feedproxy.google.com/~r/typlab/blog/~3/lT7parNRP0o/</link>
		<comments>http://blog.typlab.com/2009/09/why-we-use-haskell/#comments</comments>
		<pubDate>Tue, 22 Sep 2009 13:42:43 +0000</pubDate>
		<dc:creator>Erik</dc:creator>
				<category><![CDATA[Haskell]]></category>

		<guid isPermaLink="false">http://blog.typlab.com/?p=68</guid>
		<description><![CDATA[As a newly started company, we have a lot of technical decisions to make. One of the important ones is the choice of a programming language. Since we&#8217;re building a web application, this goes for both the client (i.e. the web browser) and the server.
On the client, there wasn&#8217;t much discussion. Javascript is the only [...]]]></description>
			<content:encoded><![CDATA[<p>As a newly started company, we have a lot of technical decisions to make. One of the important ones is the choice of a programming language. Since we&#8217;re building a web application, this goes for both the client (i.e. the web browser) and the server.</p>
<p>On the client, there wasn&#8217;t much discussion. Javascript is the only viable choice, unless you want to use Flash or similar plugin-based models. But on the server, we had more freedom. Popular choices for web applications are dynamically typed languages like Ruby, Python and PHP, and statically typed languages like Java and C#.</p>
<p>However, there was another option. Two of us (me and Sebas) are enrolled in the Software Technology master program at Utrecht University, where we often use the programming language Haskell. Haskell is a functional programming language, which means that a program is composed of expressions instead of statements, as is the case in an imperative programming language.</p>
<p>As you might have guessed from the title of this post, we decided to use Haskell for our server side programming. What are the features that made us choose Haskell?<br />
<span id="more-68"></span><br />
First, we like the functional programming model. Modeling programs based on what values are, instead of what bits to move where, is much closer to the way we think. We write down what we mean, and let the compiler figure out how to calculate it. This also leads to shorter code: Haskell is often surprisingly concise.</p>
<p>Another important consideration is the strong type system that Haskell has. It has powerful features that prevent you from running incorrect programs, while not getting in the way, as is often the case in traditional statically typed languages like Java or C#. This is due to the fact that Haskell has type inference: it can deduce the types of variables and functions without programmer specifications.</p>
<p>Something that sets Haskell apart from almost all other programming languages, is its purity: an expression in Haskell is not allowed to do anything on evaluation other than return its value (functions are not allowed to have side-effects). This has many implications. For example, data is immutable: if you modify a list, for example, you create a new copy (although smart compilers share duplicate parts for efficiency). This means that you never have to think about other parts of the code changing your data: you can always reason locally. Another implication is that your language can be lazy (and in fact, Haskell is). This means that expressions are not evaluated unless their results are needed. This can lead to performance improvements, and allows you to use infinite data structures.</p>
<p>If we disallow side effects, how do we perform I/O, for example? Haskell uses an abstraction called a monad to do this. A monad shows up in the type, indicating that we are performing side effects. The I/O monad allows us to force an ordering on actions, allowing us to safely perform the actions in a lazy setting. We can also use monads to keep state, have mutable variables, and many other things.</p>
<p>Purity also makes concurrency a lot easier: if data is immutable, there is no risk in sharing it between different threads. If you need to share mutable data between different threads, Haskell offers a few ways of dealing with this, the most interesting of which is software transactional memory (STM), a lock-free way of building composable atomic actions.</p>
<p>Since Haskell is a functional language, functions are first class: you can create them on the fly, pass them as arguments, return them as results, store them in a data structure, etc. This allows you to easily create powerful abstractions. For example, one often-used Haskell function is map. It takes an argument that turns a value of type a into a value of type b, and uses this to transform a list of a&#8217;s into a list of b&#8217;s by applying it to each element. This function abstracts away looping over a list. In a similar way we can create our own abstractions. This often leads to the creation of lightweight EDSLs (embedded domain specific languages), especially since Haskell allows the creation of (infix) operators as well.</p>
<p>The combination of conciseness, locality of data, strong types and explicit side-effects has a very important consequence: it makes refactoring easy and risk-free. You can change your code, and if it still type checks, you can often be sure that it still works. Combined with the power of abstraction this means we can quickly develop programs that can be easily understood and modified by others.</p>
<p>Finally, another positive aspect of Haskell is its community. There is an <a title="planet haskell" href="http://planet.haskell.org/">active blog community</a>, a large and helpful IRC channel (#haskell) and an <a title="Hackage" href="http://hackage.haskell.org/">online package repository</a>. There is an <a title="GHC" href="http://www.haskell.org/ghc/">industrial strength compiler</a>, a <a title="Cabal" href="http://www.haskell.org/cabal/">dependency tracking package manager</a> and built-in tools like code coverage.</p>
<p>Of course, there are also a few risks involved in choosing a language like Haskell. Since it doesn&#8217;t have a user base as large as some other languages, there are less libraries available. This is alleviated in part by a strong C interface that Haskell provides. Because of laziness, performance problems can be harder to diagnose and fix. And of course, there are less programmers who have experience with Haskell, so finding people to help you can be harder.</p>
<p>But all in all, we feel that the benefits Haskell can bring us outweigh the risks. And most of all, Haskell makes programming fun!</p>
<img src="http://feeds.feedburner.com/~r/typlab/blog/~4/lT7parNRP0o" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.typlab.com/2009/09/why-we-use-haskell/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		<feedburner:origLink>http://blog.typlab.com/2009/09/why-we-use-haskell/</feedburner:origLink></item>
		<item>
		<title>This is our lablog</title>
		<link>http://feedproxy.google.com/~r/typlab/blog/~3/_U63G-pDUVs/</link>
		<comments>http://blog.typlab.com/2009/09/this-is-our-lablog/#comments</comments>
		<pubDate>Wed, 16 Sep 2009 07:42:07 +0000</pubDate>
		<dc:creator>Lon</dc:creator>
				<category><![CDATA[Company]]></category>

		<guid isPermaLink="false">http://blog.typlab.com/?p=77</guid>
		<description><![CDATA[This is our lablog, where we will write about the proceedings of typLAB.
‘What’s typLAB then?’, you might ask.
typLAB is our initiative to investigate and develop new ways of creating and consuming web-based content. We aim to explore the boundaries of what’s possible using contemporary internet technologies. The result of our endeavors should enable you to [...]]]></description>
			<content:encoded><![CDATA[<p>This is our lablog, where we will write about the proceedings of typ<span class="lab">LAB</span>.</p>
<p>‘What’s typ<span class="lab">LAB</span> then?’, you might ask.</p>
<p>typ<span class="lab">LAB</span> is our initiative to investigate and develop new ways of creating and consuming web-based content. We aim to explore the boundaries of what’s possible using contemporary internet technologies. The result of our endeavors should enable you to read and write rich, dynamic and smart articles like you’ve never read nor written them before.</p>
<p>Next question. ‘Who are those “we” you keep referring to?’</p>
<p>We are Erik Hesselink, Sebastiaan Visser, Salar al Khafaji and Lon Boonen. That’s the team; small, smart, focused and eager to learn and share. Most of us share a history at <a href="http://www.xopus.com/">Xopus</a>, the web based XML editor.</p>
<p>One more question? ‘What about lablog, what can we expect from it?’</p>
<p>Through lablog we want to inform you of our ponderings and wonderings. Our steps forward, backward and sideways. We’ll write about our progress, our discoveries and the things that make us tick.</p>
<p>You can expect articles on HTML5, CSS3, web development in general, Haskell, XQuery, usability, semantics, JavaScript and all stuff that makes a nerd’s heart jump a beat. Or two.</p>
<p>And we&#8217;d love to hear from you. Through the comments, <a href="http://twitter.com/typLAB">Twitter</a> or plain old <a href="mailto:info@typlab.com">e-mail</a>.</p>
<img src="http://feeds.feedburner.com/~r/typlab/blog/~4/_U63G-pDUVs" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.typlab.com/2009/09/this-is-our-lablog/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://blog.typlab.com/2009/09/this-is-our-lablog/</feedburner:origLink></item>
	</channel>
</rss>
