<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Aidan Delaney's weblog &#187; General</title>
	<atom:link href="http://blogs.linux.ie/balor/category/General/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.linux.ie/balor</link>
	<description>We eat cats whilst you code.</description>
	<lastBuildDate>Thu, 02 Feb 2012 09:22:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.4</generator>
		<item>
		<title>Pipelines for visual programming languages</title>
		<link>http://blogs.linux.ie/balor/2011/11/01/pipelines-for-visual-programming-languages/</link>
		<comments>http://blogs.linux.ie/balor/2011/11/01/pipelines-for-visual-programming-languages/#comments</comments>
		<pubDate>Tue, 01 Nov 2011 22:32:01 +0000</pubDate>
		<dc:creator>balor</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Gnome]]></category>

		<guid isPermaLink="false">http://blogs.linux.ie/balor/?p=420</guid>
		<description><![CDATA[As a long time Unix user I&#8217;ve always found pilelines to be very useful. They allow you to build up extremely complex functions by sticking together much less complex parts. On Linux we put together commands and pipe the output into the next command. If you ask the question &#8220;How many mp3 files are there [...]]]></description>
			<content:encoded><![CDATA[<p>As a long time Unix user I&#8217;ve always found pilelines to be very useful.  They allow you to build up extremely complex functions by sticking together much less complex parts.  On Linux we put together commands and pipe the output into the next command.  If you ask the question &#8220;How many mp3 files are there in this directory?&#8221; you can say &#8220;Ah, I know how to list all mp3 files, and I know how to count the number of lines in a list&#8221; then the answer becomes<br />
<code><br />
$ ls -l *.mp3 | wc --lines<br />
</code><br />
Pipelines can become arbitrarily complex.  For example, the pipeline<br />
<code><br />
$ cat /var/log/maillog | grep "status=sent" | grep -v phoric | wc --lines<br />
</code><br />
counts the number of lines in my maillog that contain the text &#8220;status=sent&#8221; and omit the text &#8220;phoric&#8221; (my hostname).  There is usually someone smart enough to write a shorter pipeline than what you&#8217;ve written, but that&#8217;s not the point.  The point is that pipelines allow us to construct complex functionality by chaining together small programs.</p>
<p>If I were an academic (and I am), I&#8217;d probably generalise.  I&#8217;d say somthing like, &#8220;pipelines have a source, they have many filter and translate actions and finally an action&#8221;.  This, I believe, is a reasonable generalisation.  In a pipeline, we often take some data, strip out the bits we don&#8217;t need, translate it into another format, maybe filter some more stuff and then finally do something.  Such processes can be (relatively) easily turned into a visual programming language.  The web application <a href="http://ifttt.com/recipes?sort=popular">if this, then that</a> is a simple visual programming language.  Apple&#8217;s <a href="http://en.wikipedia.org/wiki/Automator">Automator</a> is a more general visual programming language for such pipelines on OS X.  And, going back to text-based pipelines, Window&#8217;s Powershell does away with much of the faffing about with text processing found in a Unix pipeline (by encapsulating the faffing in objects)<br />
<code><br />
Get-ChildItem C:\Scripts | Where-Object {$_.Length -gt 200KB} | Sort-Object Length<br />
</code><br />
The powershell example is <a href="http://technet.microsoft.com/en-us/library/ee176927.aspx">stolen from technet.microsoft.com</a>.</p>
<p>Let&#8217;s say I have an application area in mind.  It&#8217;s a technical area with highly complex theory such that we can expect the individual components of our pipeline to contain complex functionality.  Lets take the world of audio and video processing.  The words are technical, we can expect to <em>mux</em> (i.e. multiplex) and <em>demux</em> audio.  And we can also expect to transcode it.  Decoding, say, a flac stream and re-encoding it as a vorbis stream requires complex algorithms.  Furthermore, the language is generally well understood by geeks, like you.  So, how do I do exactly that. Open a flac file, decode it, re-encode it as a vorbis stream and save it to a file.  Fortunatly, a pipeline based toolset for audio (and video) already exists.  We&#8217;re going to look at <a href="http://en.wikipedia.org/wiki/Gstreamer">GStreamer</a>.  It&#8217;s effectively a domain-specific programming language that could be easily implemented as a visual programming language (it previously has been, but the visual side wasn&#8217;t of use to anyone who could actually understand the domain).  We want to look at how GStreamer makes constructing complex pipelines easy.</p>
<p>The following pipeline is the start of an answer our problem (it intentionally doesn&#8217;t work):<br />
<code><br />
$ gst-launch filesrc location=song.flac ! flacdec ! vorbisenc ! filesink location=song.ogg<br />
</code><br />
In the above example we construct the pipeline, where ! is the pipe symbol and launch it with <code>gst-launch</code>.  Each of the pipeline elements, on their own, are simple to understand.  A <code>filesrc</code> element reads a file at the specified <code>location</code>.  A <code>flacdec</code> element decodes a flac stream.  A <code>vorbisenc</code> element encodes something in to vorbis and a <code>filesink</code> element stores a stream back into a file.  The above pipeline produces the error<br />
<code><br />
WARNING: erroneous pipeline: could not link flacdec0 to vorbisenc0<br />
</code><br />
This is <strong>brilliant</strong>.  A major difference between a GStreamer pipeline and a Unix pipeline is that I get static checking.  It can tell me, from the structure of the pipeline, whether the type of data produced by each element, can be consumed by the following element.  This is brilliant because it saves time.</p>
<p>Imagine that my pipeline was much more complicated.  Imagine that the pipeline encoded a long, high-quality, video (taking several hours) and then tried to do something specific with the audio stream.  As a Unix pipeline it would look like<br />
<code><br />
$ cat video.raw | encodevid | modifyaudio &gt; video.webm<br />
</code><br />
We would have to run this pipeline before we saw passing of data from <code>encodevid</code> to <code>decodevid</code> failed.  So having some static checking <em>a-priori</em> (I&#8217;m an acadmeic, I&#8217;m allowed to use Latin) could save us a lot of time.  Static checking, like in a programming language, also ensures that we are passing the right data into an element that handles that data.</p>
<p>Ok, so what&#8217;s a working pipeline for the above question?<br />
<code><br />
$ gst-launch filesrc location=song.flac ! flacdec ! audioconvert ! audioresample ! vorbisenc ! oggmux ! filesink location=song.ogg<br />
</code><br />
Note: there&#8217;s a much shorter pipeline, but this one makes most of the stages explicit.  I was missing the <code>audioconvert</code><code>, the </code><code>audioresample</code> and the <code>filesink</code> steps.  Once again, this is a very complex domain.  Each of the elements in this pipeline are more simple to understand than the entire pipeline.</p>
<p>Let&#8217;s do something magic.  Take the original flac file, convert it to 8-bit audio and re-encode it as a vorbis stream in an ogg container.  Why?  Well this is the point of pipelines.  Someone might want to do this sometime.  The pipeline architecture allows you to combine elements in ways that other people may not have considered, or simply don&#8217;t need.<br />
<code><br />
$ gst-launch filesrc location=song.flac ! flacdec ! audioconvert ! audioresample ! capsfilter caps=audio/x-raw-int,channels=2,width=8,depth=8 ! audioconvert ! vorbisenc ! oggmux ! filesink location=song.ogg<br />
</code></p>
<p>I think that GStreamer is a well desiged, well implemented pipeline architecture for a complex domain.  So how does it achieve what it does?</p>
<p>Each of the elements in GStreamer advertises its capabilities.  Each element <a href="http://gstreamer.freedesktop.org/data/doc/gstreamer/head/manual/html/section-caps-api.html">advertises the capabilities</a> of what it accepts (eg: raw audio with sample freq &gt; 8hHz and &lt; 44kHz) and the capabilities of what it produces (eg: audio bit stream conforming to the vorbis spec).  You can then do static checking on pipelines by ensuring the capabilities of what is produced by one element are a subset of those consumed by the following element.  It&#039;s very neat.</p>
<p>How might you retrofit this into an existing set of complex Unix applications?  You could add a <code>--caps</code> flag (or <code>-caps</code> if you insist on BSD style) to each of your applications.  If you have no source, wrap them in a shell script that takes <code>--caps</code>.  Make the caps option outupt the input and output capabilities of your pipeline elements.  Bonus hipster points if this is outputted in JSON.  Then write a <code>my_static_checker</code> that takes your pipeline as a string, checks it statically a-la-GStreamer (I&#8217;m allowed to abuse French, I&#8217;m an academic) and then executes the pipeline.</p>
<p>Why!  Now we&#8217;re in a position to write a very domain-specific visual programming language.  This could be useful in a lot of cases.  Particularly in the case of at least one person I&#8217;ll be emailing this to.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.linux.ie/balor/2011/11/01/pipelines-for-visual-programming-languages/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Inkscape, textext and pixelated fonts</title>
		<link>http://blogs.linux.ie/balor/2011/07/04/inkscape-textext-and-pixelated-fonts/</link>
		<comments>http://blogs.linux.ie/balor/2011/07/04/inkscape-textext-and-pixelated-fonts/#comments</comments>
		<pubDate>Mon, 04 Jul 2011 22:37:02 +0000</pubDate>
		<dc:creator>balor</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://blogs.linux.ie/balor/?p=413</guid>
		<description><![CDATA[I use Inkscape a lot. Particularly for drawing diagrams for my research. I use the TexText plugin for Inkscape to allow me to embed arbitrary LaTeX in documents. However, recently I&#8217;ve had an issue with it. TexText uses pdf2svg to convert PDFs to SVGs to embed into an Inkscape project. Under the hood it runs [...]]]></description>
			<content:encoded><![CDATA[<p>I use <a href="http://www.inkscape.org">Inkscape</a> a lot.  Particularly for drawing diagrams for my research.  I use the <a href="http://pav.iki.fi/software/textext/">TexText</a> plugin for Inkscape to allow me to embed arbitrary LaTeX in documents.  However, recently I&#8217;ve had an issue with it.</p>
<p>TexText uses <a href="http://www.cityinthesky.co.uk/opensource/pdf2svg">pdf2svg</a> to convert PDFs to SVGs to embed into an Inkscape project.  Under the hood it runs pdflatex on the LaTeX fragment you provide, then it converts this to an SVG with a tight bounding box.  This has been generating horribly pixelated fonts for me.  The output of X+y=z is the following:<br /><a href="http://blogs.linux.ie/balor/files/2011/07/pixels.png"><img src="http://blogs.linux.ie/balor/files/2011/07/pixels.png" alt="Garbled output from pdf2svg" width="50" height="8" class="alignnone size-full wp-image-414" /></a></p>
<p>Having looked into it there are two ways to solve the problem</p>
<ul>
<li>The quick and simple way is to \usepackage{lmodern} at the top of your LaTeX preamble input to TexText &#8211; this forces latex to use type1 (scalable) fonts as opposed to type3 (bitmap) fonts.</li>
<li>The longer term way is to maintain textext for our research group to use.  This will involve dropping all backends other than the pdf2svg one.  Simply for the reason that I have neither the resources nor inclination to support multiple backends.  Each supported backend is a deep mine of bugs and I&#8217;m comfortable with the pdf2svg/poppler/cairo mine.</li>
</ul>
<p>I do wonder though, why LaTeX prefers type3 fonts over their type1 brethren.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.linux.ie/balor/2011/07/04/inkscape-textext-and-pixelated-fonts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FOlder &#8211; straightforward forms</title>
		<link>http://blogs.linux.ie/balor/2011/06/28/folder-straightforward-forms/</link>
		<comments>http://blogs.linux.ie/balor/2011/06/28/folder-straightforward-forms/#comments</comments>
		<pubDate>Tue, 28 Jun 2011 21:22:57 +0000</pubDate>
		<dc:creator>balor</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Haskell]]></category>

		<guid isPermaLink="false">http://blogs.linux.ie/balor/?p=403</guid>
		<description><![CDATA[So I&#8217;ve got a problem. Every year I have to gather together a set of paper based forms and put them in a folder to hand to someone for QA processing. Most of these forms start off in some word-processing package, but by the time that they require review by a colleague and multiple signatures [...]]]></description>
			<content:encoded><![CDATA[<p>So I&#8217;ve got a problem.  Every year I have to gather together a set of paper based forms and put them in a folder to hand to someone for QA processing.  Most of these forms start off in some word-processing package, but by the time that they require review by a colleague and multiple signatures they end up on paper &#8211; it&#8217;s simply easier.  But I&#8217;m not too good with paper and I&#8217;m even worse with uncodified processes that I follow once a year.  Surely there&#8217;s a way to codify a process of handling documents?  Yeah, there are plenty of tools that do it.  And here&#8217;s another&#8230;</p>
<p>FOlder gives you a web based methods of creating, and writing documents.  It&#8217;s based on the amazing <a href="http://www.aloha-editor.org/">Aloha-Editor</a> and the fantastic <a href="http://happstack.com/index.html">Happstack</a>.  So the technical plumbing is thoroughbred, using a (soon-to-be) distributed (guaranteed) ACID data store.  It&#8217;s missing three major features</p>
<ul>
<li>Authentication (coming in version 0.1),</li>
<li>Collating the created files in a folder (simple fix in version 0.2),</li>
<li>Digital signatures (straightforward to implement, hard to devise a good UI).</li>
</ul>
<p>and one minor feature</p>
<ul>
<li>upload PDFs which are viewable using <a href="http://andreasgal.com/2011/06/15/pdf-js/">PDF.js</a>.
</li>
</ul>
<p>You can find the source code <a href="http://darcsden.com/AidanDelaney/FOlder">here</a>.  I&#8217;m happy to accept patches!</p>
<p><strong>Update:</strong><br />
A quick hacked video on YouTube (uploaded in WebM so it shouldn&#8217;t require flash)</p>
<p><object width="450" height="278"><param name="movie" value="http://www.youtube.com/v/jGQPfi-DaW8?version=3"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/jGQPfi-DaW8?version=3" type="application/x-shockwave-flash" width="450" height="278" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p><a class="FlattrButton" href="http://darcsden.com/AidanDelaney/FOlder"></a><br />
<a href="http://flattr.com/thing/331345/FOlder" target="_blank"><br />
<img src="http://api.flattr.com/button/flattr-badge-large.png" alt="Flattr this" border="0" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.linux.ie/balor/2011/06/28/folder-straightforward-forms/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Three Haskell web frameworks</title>
		<link>http://blogs.linux.ie/balor/2011/06/04/three-haskell-web-frameworks/</link>
		<comments>http://blogs.linux.ie/balor/2011/06/04/three-haskell-web-frameworks/#comments</comments>
		<pubDate>Sat, 04 Jun 2011 20:52:41 +0000</pubDate>
		<dc:creator>balor</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Haskell]]></category>

		<guid isPermaLink="false">http://blogs.linux.ie/balor/?p=395</guid>
		<description><![CDATA[This model-view-controller pattern has been kicking around for quite some time now. It&#8217;s a nice way of separating concerns in many applications including web apps. And, a modern web-framework should both let you separate concerns and, ideally, bridge the gap between your programming model and data storage model. Some really nice people have done this [...]]]></description>
			<content:encoded><![CDATA[<p>This <a href="http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller">model-view-controller</a> pattern has been kicking around for quite some time now.  It&#8217;s a nice way of separating concerns in many applications including web apps.  And, a modern web-framework should both let you separate concerns and, ideally, bridge the gap between your programming model and data storage model.  Some really nice people have done this in <a href="http://rubyonrails.org/">Ruby</a> and <a href="https://www.djangoproject.com/">Python</a> and <a href="http://turbogears.org/">Python</a> and &#8230;. well you get the picture.  If you like a programming language there are probably several modern web-frameworks for it.  So can we ask that question about Haskell?  How would a modern web-framework work in a language that allows <a href="http://www.haskell.org/ghc/docs/7.0.3/html/users_guide/lang-parallel.html">easy parallelisation, straightforward concurrency and even software transactional memory</a>.  Here&#8217;s my brief take on three Haskell web frameworks, with the caveat that I&#8217;ve only used one in anger (unsurprisingly my favourite one).</p>
<p><a href="http://snapframework.com">Snap Framework</a> has been getting a lot of press lately.  It&#8217;s <strong>fast</strong>.  Faster than node.js but if you look at the documentation it appears that it uses a similar model to node.js i.e. a fast event loop.  Snap provides a templating language called Heist.  It has a nice method of handling RESTful queries (code <a href="http://snapframework.com/docs/tutorials/snap-api">stolen from here</a>)<br />
<code><br />
site :: Application ()<br />
site = route [ ("/",            index)<br />
             , ("/echo/:stuff", echo)<br />
             ]<br />
        serveDirectory "resources/static"<br />
</code><br />
Which just fires things off to specific handlers.  Nice.  And, just for good measure, I&#8217;ve stolen <a href="http://snapframework.com/docs/tutorials/heist">this heist snippet</a> too<br />
<code><br />
&lt;html&gt;<br />
    &lt;head&gt;<br />
      &lt;title&gt;Home Page&lt;/title&gt;<br />
    &lt;/head&gt;<br />
    &lt;body&gt;<br />
      &lt;h1&gt;Home Page&lt;/h1&gt;<br />
      &lt;apply template="nav"/&gt;<br />
      &lt;p&gt;Welcome to our home page&lt;/p&gt;<br />
    &lt;/body&gt;<br />
  &lt;/html&gt;<br />
</code><br />
Snap leaves the choice of a storage backend up to the developer.  They&#8217;ve got good reasons for this, however if doesn&#8217;t endear me.  I&#8217;m happer with smart people doing all the integration work and giving me something to use.</p>
<p><a href="http://www.yesodweb.com">Yesod</a> gives you the choice of using either sqlite or postgres as a backing store.  And it&#8217;ll do automagic migration of database schemas.  Defining a datatype for storage is simple<br />
<code><br />
mkPersist [$persist|<br />
    Entry<br />
        title String<br />
        day Day Desc<br />
        content Html'<br />
        deriving<br />
    |]<br />
</code><br />
Again, this code is stolen from the <a href="http://www.yesodweb.com/page/screencasts">very excellent tutorial</a>.  But this is looking straightforward, I get a Haskell datatype that&#8217;s persisted to a standard, trustworthy relational data store.  Now, the people who are writing Snap seem to be scary smart and like to make fast things even faster, but this guy who develops Yesod seems to want to give me all the tools I need to just make a web app.  It&#8217;s worth looking at his screencasts to see how easy OpenID and Facebook authentication is in a Yesod app.  Furthermore, Yesod provides Hamlet, Cassius and Julius &#8211; respectively HTML, CSS and JavaScript templating languages.  Julius, in particular, seems to have been designed with jQuery in mind.  This, again, makes sense to me. Someone is giving me great tools to produce web apps under the standard use-case i.e. nice RESTful blingy things.  You can even see that the <a href="http://www.yesodweb.com/page/screencasts">Yesod query routing</a> is simple<br />
<code><br />
mkYesod "Blog" [$parseRoutes|<br />
/ RootR GET<br />
/entry/#EntryId EntryR GET<br />
/admin AdminR EntryCrud defaultCrud<br />
|]<br />
</code></p>
<p>And finally we get to <a href="http://happstack.com/">Happstack</a>.  Happstack is the most mature of the three and features a <strong>wonderful</strong> data store called <a href="http://acid-state.seize.it/">MACID</a>.  MACID has <a href="http://en.wikipedia.org/wiki/ACID">acid</a> super powers but it <strong>distributes</strong>.  I get to store any Haskell structure I want in a secure, distributed data-store!  Representing reasonably complex information is easy<br />
<code><br />
$(deriveAll [''Show, ''Eq, ''Ord, ''Default]<br />
  [d|<br />
      -- |ConferenceSubmission: a paper submitted to the conference<br />
      data ConferenceSubmission = ConferenceSubmission<br />
          { author  :: String<br />
          , title :: String<br />
          , date    :: ClockTime<br />
          , email :: String<br />
          }</p>
<p>      -- |Conference: a list of ConferenceSubmission<br />
      newtype Conference = Conference { conferenceSubmissions :: [ConferenceSubmission] }<br />
   |])<br />
</code><br />
Routing is a little hairy, but you get a lot of power from it.  And it&#8217;s nicely monadic.<br />
<code><br />
appHandler =<br />
    do decodeBody (defaultBodyPolicy "/tmp/" 4096 4096 4096) -- decode the request body if present.<br />
       msum [ methodM GET &gt;&gt; renderIndex -- matches /<br />
              , renderSubmissions =&lt;&lt; conferenceHandler<br />
            ]<br />
conferenceHandler :: ServerPartT IO (HSP XML)<br />
conferenceHandler =<br />
  dir &quot;submissions&quot; $ msum [postSubmission, getEntries]        -- RESTful /submissions<br />
</code><br />
Happstack uses <a href="http://happstack.com/docs/crashcourse/Templates.html">Blaze or HSP</a> or many other options for its templating language.  Again, Blaze and HSP both play well with jQuery.</p>
<p>I have a fun project to play with over the next few months.  I think Happstack is what I&#8217;ll be using.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.linux.ie/balor/2011/06/04/three-haskell-web-frameworks/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Further homage to QuickCheck</title>
		<link>http://blogs.linux.ie/balor/2011/05/20/further-homage-to-quickcheck/</link>
		<comments>http://blogs.linux.ie/balor/2011/05/20/further-homage-to-quickcheck/#comments</comments>
		<pubDate>Fri, 20 May 2011 11:55:22 +0000</pubDate>
		<dc:creator>balor</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://blogs.linux.ie/balor/?p=388</guid>
		<description><![CDATA[Lets suppose you&#8217;ve got two similar recursive types that differ only in their &#8220;payload&#8221;. For example, you want a binary tree of boolean operations to store a Char and another similar tree to store a set of Char. Let&#8217;s call them Tree and STree. Something like in the following, non-working, code data Tree = And [...]]]></description>
			<content:encoded><![CDATA[<p>Lets suppose you&#8217;ve got two similar recursive types that differ only in their &#8220;payload&#8221;.  For example, you want a binary tree of boolean operations to store a Char and another similar tree to store a set of Char.  Let&#8217;s call them Tree and STree.  Something like in the following, non-working, code</p>
<pre>
data Tree = And Tree Tree
  | Or Tree Tree
  | Leaf Char

data STree = And STree STree
  | Or STree STree
  | Leaf (Set Char)
</pre>
<p>We&#8217;re repeating a lot of boiler plate here.  It&#8217;d be great if I could parameterise the tree, which I can.</p>
<pre>
data MTree t = And (MTree t) (MTree t)
  | Or (MTree t) (MTree t)
  | Leaf t
</pre>
<p>This is great, it removes boilerplate, and gives me less code to test.</p>
<p>Take our Tree as defined above.  It&#8217;s easy to create an Arbitrary Tree.  The following code creates an arbitrary tree with a maximum branch depth (generally for efficiency reasons you don&#8217;t want test trees that are either (arbitrary :: Int) or infinitely deep)</p>
<pre><font color="Green"><u>import</u></font> Test<font color="Cyan">.</font>QuickCheck
<font color="Green"><u>import</u></font> Control<font color="Cyan">.</font>Monad

<font color="Green"><u>data</u></font> Tree <font color="Red">=</font> And Tree Tree
  <font color="Red">|</font> Or Tree Tree
  <font color="Red">|</font> Leaf Char
  <font color="Green"><u>deriving</u></font> Show

<font color="Blue">arbitraryTree</font> <font color="Red">::</font> Int <font color="Red">-&gt;</font> Gen Tree
<font color="Blue">arbitraryTree</font> <font color="Magenta">0</font>        <font color="Red">=</font>
  <font color="Green"><u>do</u></font>
    c <font color="Red">&lt;-</font> arbitrary
    return <font color="Cyan">(</font>Leaf c<font color="Cyan">)</font>
<font color="Blue">arbitraryTree</font> maxDepth <font color="Red">=</font>
  <font color="Green"><u>do</u></font>
    t <font color="Red">&lt;-</font> oneof <font color="Red">[</font>arbitraryTree <font color="Magenta">0</font><font color="Cyan">,</font>
                liftM2 And <font color="Cyan">(</font>arbitraryTree depth'<font color="Cyan">)</font> <font color="Cyan">(</font>arbitraryTree depth'<font color="Cyan">)</font><font color="Cyan">,</font>
                liftM2 Or <font color="Cyan">(</font>arbitraryTree depth'<font color="Cyan">)</font> <font color="Cyan">(</font>arbitraryTree depth'<font color="Cyan">)</font><font color="Red">]</font>
    return t
  <font color="Green"><u>where</u></font>
    depth' <font color="Red">=</font> maxDepth <font color="Blue"><i>-</i></font><font color="Magenta">1</font>

<font color="Green"><u>instance</u></font> Arbitrary Tree <font color="Green"><u>where</u></font>
  arbitrary <font color="Red">=</font> <font color="Green"><u>do</u></font>
    maxDepth <font color="Red">&lt;-</font> choose <font color="Cyan">(</font><font color="Magenta">1</font><font color="Cyan">,</font> <font color="Magenta">10</font><font color="Cyan">)</font>
    t <font color="Red">&lt;-</font> arbitraryTree maxDepth
    return t
</pre>
<p>So how do you create an arbitrary MTree?  The following code makes it all work.</p>
<pre><font color="Green"><u>import</u></font> Test<font color="Cyan">.</font>QuickCheck
<font color="Green"><u>import</u></font> Control<font color="Cyan">.</font>Monad

<font color="Green"><u>data</u></font> MTree t <font color="Red">=</font> And <font color="Cyan">(</font>MTree t<font color="Cyan">)</font> <font color="Cyan">(</font>MTree t<font color="Cyan">)</font>
  <font color="Red">|</font> Or <font color="Cyan">(</font>MTree t<font color="Cyan">)</font> <font color="Cyan">(</font>MTree t<font color="Cyan">)</font>
  <font color="Red">|</font> Leaf t
  <font color="Green"><u>deriving</u></font> Show

<font color="Blue">arbitraryMTree</font> <font color="Red">::</font> Arbitrary t <font color="Red">=&gt;</font> Int <font color="Red">-&gt;</font> Gen <font color="Cyan">(</font>MTree t<font color="Cyan">)</font>
<font color="Blue">arbitraryMTree</font> <font color="Magenta">0</font>        <font color="Red">=</font>
  <font color="Green"><u>do</u></font>
    c <font color="Red">&lt;-</font> arbitrary
    return <font color="Cyan">(</font>Leaf c<font color="Cyan">)</font>
<font color="Blue">arbitraryMTree</font> maxDepth <font color="Red">=</font>
  <font color="Green"><u>do</u></font>
    tr <font color="Red">&lt;-</font> oneof <font color="Red">[</font>arbitraryMTree <font color="Magenta">0</font><font color="Cyan">,</font>
                liftM2 And <font color="Cyan">(</font>arbitraryMTree depth'<font color="Cyan">)</font> <font color="Cyan">(</font>arbitraryMTree depth'<font color="Cyan">)</font><font color="Cyan">,</font>
                liftM2 Or <font color="Cyan">(</font>arbitraryMTree depth'<font color="Cyan">)</font> <font color="Cyan">(</font>arbitraryMTree depth'<font color="Cyan">)</font><font color="Red">]</font>
    return tr
  <font color="Green"><u>where</u></font>
    depth' <font color="Red">=</font> maxDepth <font color="Blue"><i>-</i></font><font color="Magenta">1</font>

<font color="Green"><u>instance</u></font> Arbitrary t <font color="Red">=&gt;</font> Arbitrary <font color="Cyan">(</font>MTree t<font color="Cyan">)</font> <font color="Green"><u>where</u></font>
  arbitrary <font color="Red">=</font> <font color="Green"><u>do</u></font>
    maxDepth <font color="Red">&lt;-</font> choose <font color="Cyan">(</font><font color="Magenta">1</font><font color="Cyan">,</font> <font color="Magenta">10</font><font color="Cyan">)</font>
    tr <font color="Red">&lt;-</font> arbitraryMTree maxDepth
    return tr
</pre>
<p>This is remarkably neat.  QuickCheck, for me, is the killer feature of functional programming!</p>
<p>Returning to the <a href="http://blogs.linux.ie/balor/2011/05/17/creating-arbitrary-foo-for-quickcheck/">Squad example</a> from the other day.  We can create Arbitrary instances of Squad.</p>
<pre>
import Data.Set
import Data.List
import Test.QuickCheck
import Control.Monad

data Squad a = Squad { players :: (Set a), team :: a}

instance (Ord a, Arbitrary a) =&gt; Arbitrary (Squad a) where
  arbitrary =
    do
    ps &lt;- listOf1 arbitrary
    t &lt;- elements ps
    return (Squad (fromList ps) t)
</pre>
<p>But now I have a complication (and this is where the Squad metaphor breaks down, but please bare with me).  Suppose I want a Squad of players where I can in some instances choose a subset of them to play, and in other instances only choose one of them to play.  So the Squad still constains a set of players, but the team can sometimes be a subset of the players, and sometimes is a single player.  We&#8217;ve got to allow instances of TypeSynonyms:</p>
<pre><font color="Blue"><i>{-# LANGUAGE TypeSynonymInstances #-}</i></font>
<font color="Green"><u>import</u></font> Data<font color="Cyan">.</font>Set
<font color="Green"><u>import</u></font> Data<font color="Cyan">.</font>List
<font color="Green"><u>import</u></font> Test<font color="Cyan">.</font>QuickCheck
<font color="Green"><u>import</u></font> Control<font color="Cyan">.</font>Monad

<font color="Green"><u>data</u></font> Squad a b <font color="Red">=</font> Squad <font color="Cyan">{</font> players <font color="Red">::</font> <font color="Cyan">(</font>Set a<font color="Cyan">)</font><font color="Cyan">,</font> team <font color="Red">::</font> b<font color="Cyan">}</font>
<font color="Green"><u>type</u></font> SetSquad <font color="Red">=</font> Squad Char <font color="Cyan">(</font>Set Char<font color="Cyan">)</font>
<font color="Green"><u>type</u></font> SingleSquad <font color="Red">=</font> Squad Char Char

<font color="Green"><u>instance</u></font> Arbitrary SetSquad <font color="Green"><u>where</u></font>
  arbitrary <font color="Red">=</font>
    <font color="Green"><u>do</u></font>
    ps <font color="Red">&lt;-</font> listOf1 arbitrary
    t <font color="Red">&lt;-</font> elements <font color="Cyan">(</font>subsequences ps<font color="Cyan">)</font>
    return <font color="Cyan">(</font>Squad <font color="Cyan">(</font>fromList ps<font color="Cyan">)</font> <font color="Cyan">(</font>fromList t<font color="Cyan">)</font><font color="Cyan">)</font>

<font color="Green"><u>instance</u></font> Arbitrary SingleSquad <font color="Green"><u>where</u></font>
  arbitrary <font color="Red">=</font>
    <font color="Green"><u>do</u></font>
    ps <font color="Red">&lt;-</font> listOf1 arbitrary
    t <font color="Red">&lt;-</font> elements ps
    return <font color="Cyan">(</font>Squad <font color="Cyan">(</font>fromList ps<font color="Cyan">)</font> t<font color="Cyan">)</font>
</pre>
<p>Which is awesome.</p>
<p>Mad props to my homeboy <a href="http://koweycode.blogspot.com/">Eric</a> (I&#8217;ve been told that&#8217;s how one addresses a USian) for listening to my overtired ramblings last night, and for pointing me at numerous ways to implement what I wanted to.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.linux.ie/balor/2011/05/20/further-homage-to-quickcheck/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Recursive types in QuickCheck</title>
		<link>http://blogs.linux.ie/balor/2011/05/18/recursive-types-in-quickcheck/</link>
		<comments>http://blogs.linux.ie/balor/2011/05/18/recursive-types-in-quickcheck/#comments</comments>
		<pubDate>Wed, 18 May 2011 19:55:26 +0000</pubDate>
		<dc:creator>balor</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://blogs.linux.ie/balor/?p=385</guid>
		<description><![CDATA[I want to build arbitrary sized trees of Compound data Compound = And Compound Compound &#124; Or Compound Compound &#124; Product Compound Compound &#124; Not Compound &#124; Leaf { diagram :: Unitary} deriving (Show, Eq) However, I want to limit to a max depth, and I want to have each branch to be of an [...]]]></description>
			<content:encoded><![CDATA[<p>I want to build arbitrary sized trees of <code>Compound</code></p>
<pre>
<font color="Green"><u>data</u></font> Compound <font color="Red">=</font> And Compound Compound
  <font color="Red">|</font> Or Compound Compound
  <font color="Red">|</font> Product Compound Compound
  <font color="Red">|</font> Not Compound
  <font color="Red">|</font> Leaf <font color="Cyan">{</font> diagram <font color="Red">::</font> Unitary<font color="Cyan">}</font> <font color="Green"><u>deriving</u></font> <font color="Cyan">(</font>Show<font color="Cyan">,</font> Eq<font color="Cyan">)</font>
</pre>
<p>However, I want to limit to a max depth, and I want to have each branch to be of an arbitrary depth.</p>
<pre>
<font color="Blue">mkBinary</font> <font color="Red">::</font> <font color="Cyan">(</font>Compound <font color="Red">-&gt;</font> Compound <font color="Red">-
&gt;</font> Compound<font color="Cyan">)</font> <font color="Red">-&gt;</font> Int <font color="Red">-&gt;</font> Gen Compound
<font color="Blue">mkBinary</font> f depth <font color="Red">=</font>
  liftM2 f <font color="Cyan">(</font>mkCompound depth'<font color="Cyan">)</font> <font color="Cyan">(</font>mkCompound depth'<font color="Cyan">)</font>
  <font color="Green"><u>where</u></font>
    depth' <font color="Red">=</font> depth <font color="Blue"><i>-</i></font><font color="Magenta">1</font>

<font color="Blue">mkNot</font> <font color="Red">::</font> Int <font color="Red">-&gt;</font> Gen Compound
<font color="Blue">mkNot</font> depth <font color="Red">=</font>
  liftM Not <font color="Cyan">(</font>mkCompound <font color="Cyan">(</font>depth<font color="Blue"><i>-</i></font><font color="Magenta">1</font><font>)</font><font color="Cyan">)</font>

<font color="Blue">mkLeaf</font> <font color="Red">::</font> Gen Compound
<font color="Blue">mkLeaf</font> <font color="Red">=</font> liftM Leaf arbitrary

<font color="Blue">mkCompound</font> <font color="Red">::</font> Int <font color="Red">-&gt;</font> Gen Compound
<font color="Blue">mkCompound</font> <font color="Magenta">0</font> <font color="Red">=</font> mkLeaf
<font color="Blue">mkCompound</font> depth <font color="Red">=</font> oneof <font color="Red">[</font>mkLeaf<font color="Cyan">,</font> mkBinary And depth, mkBinary Or depth<font color="Cyan">,</font> mkBinary Product depth<font color="Cyan">,</font> mkNot depth<font color="Red">]

</font><font color="Green"><u>instance</u></font> Arbitrary Compound <font color="Green"><u>where</u></font>
  arbitrary <font color="Red">=</font>
    <font color="Green"><u>do</u></font> depth <font color="Red">&lt;-</font> choose <font color="Cyan">(</font><font color="Magenta">0</font><font color="Cyan">,</font> <font color="Magenta">4</font><font color="Cyan">)</font>
       d <font color="Red">&lt;-</font> mkCompound depth
       return d
</pre>
<p>QuickCheck can do it.  It&#8217;s nice.  Use it.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.linux.ie/balor/2011/05/18/recursive-types-in-quickcheck/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating Arbitrary Foo for QuickCheck</title>
		<link>http://blogs.linux.ie/balor/2011/05/17/creating-arbitrary-foo-for-quickcheck/</link>
		<comments>http://blogs.linux.ie/balor/2011/05/17/creating-arbitrary-foo-for-quickcheck/#comments</comments>
		<pubDate>Tue, 17 May 2011 14:48:19 +0000</pubDate>
		<dc:creator>balor</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[Teaching]]></category>

		<guid isPermaLink="false">http://blogs.linux.ie/balor/?p=377</guid>
		<description><![CDATA[I always write semi-automated tests, whatever language I&#8217;m using. In Haskell my preferred framework is QuickCheck, which goes beyond what an XUnit framework is capable of. I come to QuickCheck as a convert from the old religion of Object Oriented programming. However much I&#8217;ve adopted functional practices I find myself, in the darkest of times, [...]]]></description>
			<content:encoded><![CDATA[<p>I always write <a href="http://blog.ezyang.com/2011/02/semi-automatic-testing/">semi-automated tests</a>, whatever language I&#8217;m using.  In Haskell my preferred framework is QuickCheck, which goes beyond what an XUnit framework is capable of.  I come to QuickCheck as a convert from the old religion of Object Oriented programming.  However much I&#8217;ve adopted functional practices I find myself, in the darkest of times, falling back on idioms from a past life.  Recently I&#8217;ve been testing code that looks like the following:<br />
<code><br />
data Squad = Squad { players :: Set Char,<br />
                                 team :: Set Char }<br />
</code><br />
So what I&#8217;ve got is some type which is composed of a set and some other set which is a subset of the original.  I hope the Squad metaphor is reasonable.  In many sports you&#8217;ll have a panel of players, called the squad, and then for any given game you&#8217;ll have a team which is a subset of the players in your squad.  To simplify this problem, each player is identified by a single character rather than a name.  Now, we don&#8217;t have a <a href="http://en.wikipedia.org/wiki/Dependent_type">dependent</a> type system here.  Just plain old Haskell.  So the constraint that &#8220;team is a subset of players&#8221; is not enforced by the type system.</p>
<p>Now I want to tell Haskell to create Arbitrary instances of Squad.<br />
<code><br />
randSubset :: Ord a =&gt; Set a -&gt; Gen (Set a)<br />
randSubset xs = do {<br />
        mask &lt;- vectorOf (Set.size xs) arbitrary;<br />
        return  (Set.fromList [ e | (e,True) &lt;- zip (Set.toList xs) mask ]) }</p>
<p>instance Arbitrary Squad where<br />
  arbitrary = do {<br />
    players &lt;- listOf1 (arbitrary :: Gen Char);<br />
    team &lt;- randSubset (Set.fromList players);<br />
    return (Squad (Set.fromList players) team))}<br />
</code><br />
The smarts here is in <code>randSubset</code>, but listOf1 ensures that there&#8217;s at least one player in our squad.  I was struggling when playing around with a random number generator, to try and pull out random elements from a Set.  Such thinking is a false idol.  With some guidance from the only <a href="http://koweycode.blogspot.com/">person</a> on the planet to be 90% Real Jedi I realised you can just use the <a href="http://hackage.haskell.org/packages/archive/QuickCheck/latest/doc/html/Test-QuickCheck-Gen.html">common generator combinators</a> as provided by QuickCheck.</p>
<p>So the fragment<br />
<code><br />
do {<br />
  mask &lt;- vectorOf (Set.size xs) arbitrary;<br />
  return  (Set.fromList [ e | (e,True) &lt;- zip (Set.toList xs) mask ])}<br />
</code><br />
asks for an arbitrary list of boolean values where the list is the same length as the size of the input Set.  Then where the ith element of the list is true, the ith element of the set is considered to be in the subset, or omitted otherwise.  It&#8217;s a nice idiom, useful anywhere you&#8217;re playing with sets that aren&#8217;t quite arbitrary themselves, but are constrained to be a subset of another.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.linux.ie/balor/2011/05/17/creating-arbitrary-foo-for-quickcheck/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>An issue with QuickCheck 2</title>
		<link>http://blogs.linux.ie/balor/2011/05/07/an-issue-with-quickcheck-2/</link>
		<comments>http://blogs.linux.ie/balor/2011/05/07/an-issue-with-quickcheck-2/#comments</comments>
		<pubDate>Sat, 07 May 2011 20:05:27 +0000</pubDate>
		<dc:creator>balor</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://blogs.linux.ie/balor/?p=365</guid>
		<description><![CDATA[I&#8217;ve been interested in functional programming for a while. I&#8217;ve hacked up a few things. Mira and Conferenceasaurus mainly. I&#8217;m not claiming that the code is great, I&#8217;d regard myself still as a n00b. I also have an interest in software testing, to this end the QuickCheck is both interesting and awesome. However, I&#8217;ve got [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been interested in functional programming for a while.  I&#8217;ve hacked up a few things. <a href="https://patch-tag.com/r/balor/Mira">Mira</a> and <a href="https://patch-tag.com/r/balor/conferenceasaurus/">Conferenceasaurus</a> mainly.  I&#8217;m not claiming that the code is great, I&#8217;d regard myself still as a n00b.  I also have an interest in software testing, to this end the <a href="http://hackage.haskell.org/packages/archive/QuickCheck/latest/doc/html/Test-QuickCheck.html">QuickCheck</a> is both interesting and awesome.  However, I&#8217;ve got one significant issue with my usage of it.</p>
<p>The types I&#8217;m playing with should probably be implemented using a dependent type system.  For example, I&#8217;ve got a lot of<br />
<code><br />
data Foo = Foo {bar::Set a, quux::Set a}<br />
</code><br />
where quux should be a subset of bar.  I&#8217;m not using a dependent type system, just regular Haskell, so the dependence is not enforced.  However, I do want to generate instances of <code>Arbitrary Foo</code> where <code>quux</code> is a random subset of <code>bar</code>.  Randomness is where my issues lie.</p>
<p>I could generate a random subset of a set<br />
<code><br />
import Data.Set<br />
import Data.Maybe<br />
import Test.QuickCheck</p>
<p>randSubset :: Set a -&gt; Gen (Set a)<br />
randSubset xs = do {<br />
           mask &lt;- vectorOf (size xs) (arbitrary::Gen Bool);<br />
           return  (fromList (catMaybes [if b then (Just e) else Nothing | e &lt;- l, b &lt;- mask]))<br />
           }<br />
           where<br />
           l = toList xs<br />
</code><br />
However, you&#8217;ll notice that the type signature is <code>randSubset :: Set a -&gt; Gen (Set a)</code> and to create <code>quux</code> as a random subset of <code>bar</code> in an <code>Arbitrary Foo</code> I&#8217;d need this to return a <code>Set a</code>.  I could <a href="http://hackage.haskell.org/packages/archive/QuickCheck/latest/doc/html/Test-QuickCheck-Gen.html#v:unGen"><code>unGen</code></a> it, however this would require picking a seed which produces the same set of pseudo-random numbers each time, or generating a random seed, in which case I&#8217;d have to return an <code>IO (Set a)</code>.</p>
<p>So, question time.  Is it possible to generate arbitrary instances of <code>Foo</code> such that the property &#8220;quux is a subset of bar&#8221; is enforced in all arbitrary instances?</p>
<p><strong>update:</strong><br />
As <code>arbitrary :: Gen a</code> then <code>arbitrary = do x &lt;- arbitrary; y &lt;- randSubset x; return (Foo x y)</code> is the solution.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.linux.ie/balor/2011/05/07/an-issue-with-quickcheck-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A tough Q1 for open-source</title>
		<link>http://blogs.linux.ie/balor/2011/03/25/a-tough-q1-for-open-source/</link>
		<comments>http://blogs.linux.ie/balor/2011/03/25/a-tough-q1-for-open-source/#comments</comments>
		<pubDate>Fri, 25 Mar 2011 10:18:25 +0000</pubDate>
		<dc:creator>balor</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Gnome]]></category>

		<guid isPermaLink="false">http://blogs.linux.ie/balor/?p=351</guid>
		<description><![CDATA[You can feel the recession biting. It seems to have encouraged several companies to evaluate their open-source strategy. Actually, maybe that reasoning is a little too shallow. There are some deeper reasons we&#8217;ve seen Nokia, Google and RedHat change some of their practices. But let&#8217;s be clear from the start; some companies, like Nokia, have [...]]]></description>
			<content:encoded><![CDATA[<p>You can feel the recession biting.  It seems to have encouraged several companies to evaluate their open-source strategy.  Actually, maybe that reasoning is a little too shallow.  There are some deeper reasons we&#8217;ve seen Nokia, Google and RedHat change some of their practices.   But let&#8217;s be clear from the start; some companies, like Nokia, have changed their whole strategy.  Others, like RedHat, have made little corrections to their general practice.  Nokia made their strategic decision based on failure and RedHat made their practice change due to success.</p>
<p>The Nokia thing.  They&#8217;ve executed an entire U-turn on their open-source strategy.  At a high-level their previous strategy seemed to be (as an external observer) to use their excellent <a href="http://qt.nokia.com/">QT</a> toolkit to develop applications for their newly open-sourced <a href="http://en.wikipedia.org/wiki/Symbian_OS">Symbian</a> platform for low to mid-range mobiles.  Furthermore, they&#8217;d use the same toolkit to develop for their next-gen <a href="http://meego.com/">Meego</a> platform.  However, for reasons to do with both business and technology, they&#8217;ve decided that Windows Phone 7 is to be their next-gen platform of choice.  Thankfully, the open-source nature of Meego means that we <a href="http://www.linuxfoundation.org/lp/page/meego">don&#8217;t loose the innovation</a> that has been already contributed to the platform.</p>
<p>The reasons for Nokia&#8217;s change have been extensively covered in the computing press.  My take is that the major consequence of this is an observation that all of our next-gen mobile platform providers are non-European (yes I&#8217;m discounting Symbian).  So Android is from Google, WP7 from Microsoft, WebOS from HP and Blackberry from RIM.  The first three are US companies, the last is Canadian.  This, in my opinion, is a bad thing for Europe.  Much of the Nokia R&amp;D on Meego seemed to be outsourced to small to medium sized European companies.  I know of at least three British companies (I have resided in the UK for a few years now) that did Meego development which was paid for by Nokia.  </p>
<p>On Google&#8217;s  <a href="http://www.theregister.co.uk/2011/03/24/google_will_not_open_source_android_honeycomb_on_release_of_first_devices/">Honeycomb decision</a>.  I&#8217;ve not decided yet if this is in response to </p>
<ol>
<ul>The Chinese strawman argument, or</ul>
<ul>Some deep-integration argument.</ul>
</ol>
<p>Maybe it&#8217;s both or neither.  However, the Chinese strawman is the argument that if Honeycomb is open-source then many companies come along and produce poor-quality, but cheap, devices running the platform.  Therefore, devaluing the perception of the platform.  I believe that this argument is a poor one, hence I&#8217;ve called it a strawman.  I don&#8217;t see how Android resellers can charge the 30% markup that one of their competitors can charge.  Maybe this allows the small number of honeycomb licensees to bump up their margins slightly?</p>
<p>The deep integration argument is that honeycomb is bound to a specific platform like NVidia&#8217;s Tegra. Or, more interestingly, Google don&#8217;t think that you can do really high-quality UX design in an open-source fashion.  There&#8217;s been a lot of talk about this lately in the open source world.  About the open-source world being <a href="http://smarterware.org/7550/designers-women-and-hostility-in-open-source">hostile to designers</a>.  One aspect of this has been the <a href="http://blogs.gnome.org/bolsh/2011/03/11/lessons-learned/">Canonical/Gnome</a> argument.  Where, it appears, that Canonical decided that the best way to design their next-gen desktop was to bring the design team in-house (it&#8217;s more grey than in-house -v- not in-house) whereas the Gnome team are (almost) <a href="http://gitorious.org/gnome-design">entirely open</a> and have even developed the fantabulous <a href="http://www.sparkleshare.org/">sparkle share</a> tool for sharing designs between Gnome designers.  What&#8217;s clear is that good UX design is hard.  What&#8217;s unclear is whether being open-source makes good UX more difficult.  I think that <a href="http://thinkupapp.com/">ThinkUp</a>, <a href="http://www.mozilla.com/en-US/firefox/fx/">Firefox</a> and <a href="http://www.gnome3.org/">Gnome 3</a> make good design stories.  For the record, I think Caonical&#8217;s Unity is interesting but doesn&#8217;t add anything to the point I&#8217;m trying to make.</p>
<p>I don&#8217;t know the ThinkUp people.  But they seem to have a great attitude to encouraging contributions from people who might have traditionally found open-source hostile.  From an external perspective, they seem to do great design in a small team and apply it to a hosted web application.  Web designers are awesome.  They&#8217;ve, arguably, made more design progress in the past ten years than desktop designers have made in the past thirty.  Those of us who build fat (desktop) apps can then borrow their design ideas.</p>
<p>The Firefox devs are entirely different.  It&#8217;s a massive project.  They have different design constraints than ThinkUp, particularly as they have such a massive install base on so many different platforms.  Furthermore, Mozilla has a lot of cash to spend on both user testing and a team of UX desigers.  I like Firefox 4.  I think you can see the fruits of incremental, good design.</p>
<p>The design community I&#8217;m most familiar with are the <a href="http://gnome3.org/">Gnome 3</a> designers.  What they&#8217;ve done in the past six months is amazing.  Furthermore, unlike the small integrated team at ThinkUp or the large on-site team at Mozilla, the Gnome design team is distributed (in terms of geography and companies) but well-integrated.<br />
<img src="http://www.gnome3.org/img/overview-big.png" /><br />
<br />
This picture speaks more than a paragraph of text.  It shows a clean and consistent desktop.  Yes there are a few unpolished edges, but the software hasn&#8217;t been released yet.  What&#8217;s interesting is to observe the &#8220;traditional code geeks&#8221; talking to the UX designers.  Changes to the UI or the UX are, more often than not, bounced off one of the designers.  And, more interesting, is that the ideas that the UX designers communicate are being internalised by the developers.  Ok, so very few of these developers will ever be kick-ass designers.  However, by internalising the design ideas you can see a commitment to bringing fresh UX ideas on board and the value that the developers place on the design team.  They&#8217;re highly valued and stunningly smart people.</p>
<p>So as usual I started off talking about how this Q1 has been tough for open-source.  However my internal optimist has trumped my internal cynic.  Nokia and Google may make decisions about their open-source policy, but they&#8217;re not the only places that are (or were) doing excellent open-source design and engineering.  The loss of Nokia from our ecosystem will be keenly felt.  But Intel are pressing forward with Meego and the design ideas that come from Meego are finding their way into Gnome 3 (and vice-versa).</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.linux.ie/balor/2011/03/25/a-tough-q1-for-open-source/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Cubic spline interpolation</title>
		<link>http://blogs.linux.ie/balor/2011/01/30/cubic-spline-interpolation/</link>
		<comments>http://blogs.linux.ie/balor/2011/01/30/cubic-spline-interpolation/#comments</comments>
		<pubDate>Sun, 30 Jan 2011 17:39:29 +0000</pubDate>
		<dc:creator>balor</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://blogs.linux.ie/balor/?p=346</guid>
		<description><![CDATA[The following may make more sense when the latex-mathjax plugin is enabled. You&#8217;ll see the equations then, not the LaTeX source. I&#8217;ve got a set of $(x,y)$ points. What I want to do is draw a reasonably smooth curve through all of them, rather than a set of straight lines connecting them. To do so, [...]]]></description>
			<content:encoded><![CDATA[<p>The following may make more sense when the latex-mathjax plugin is enabled.  You&#8217;ll see the equations then, not the LaTeX source.</p>
<p>I&#8217;ve got a set of $(x,y)$ points.  What I want to do is draw a reasonably smooth curve through all of them, rather than a set of straight lines connecting them.  To do so, I need some higher order function such as a cubic.  In particular the cubic Bezier function is a well known graphics primitive.  Therefore, given a set of points and the definition of a cubic Bezier, I need to calculate the control points for each curve.</p>
<p>A cubic Bezier function interpolates between $K_0$ and $K_1$ using control points $C_{0,1}$ and $C_{0,2}$ in the following manner<br />
$$<br />
B(t)=(1-t)^3K_0+3t(1-t)^2C_{0,1}+3t^2(1-t)C_{0,2}+t^3K_1.<br />
$$<br />
We may extend the idea to a spline.  The knots of the spline are $\langle K_0, K_1,\ldots,K_n\rangle$.  This leads to $n-1$ cubic functions $B_0, B_1, \ldots, B_{n-1}$.  Where $B_i$ interpolates between $K_i$ and $K_{i+1}$ with control points $C_{i,1}$ and $C_{i,2}$.</p>
<p>We want $C^2$ continuity so that our curve is nice and smooth.  Therefore, for each $i$ we require<br />
\begin{eqnarray*}<br />
B^\prime_i(1)&amp;=&amp;B^\prime_{i+1}(0)\textrm{ and}\\<br />
B^{\prime\prime}_i(1)&amp;=&amp;B^{\prime\prime}_{i+1}(0).<br />
\end{eqnarray*}<br />
Furthermore,<br />
$$<br />
B_i^\prime(t)=3K_{i+1}t^2-3C_{i,2}t^2+6C_{i,2}\left(1-t\right)t-6C_{i,1}\left(1-t\right)t+3C_{i,1}\left(1-t\right)^2-3K_i\left(1-t\right)^2<br />
$$<br />
and<br />
$$<br />
B_i^{\prime\prime}(t)=6 K_i (1 &#8211; t) + 6 C_{i,1} t  &#8211; 12 C_{i,1} (1 &#8211; t) &#8211; 12 C_{i,2} t  + 6 C_{i,2} (1 &#8211; t) + 6 K_{i+1} t.<br />
$$</p>
<p>Evaluating $B^\prime_i(1)$ gives<br />
\begin{eqnarray*}<br />
B_i^\prime(1)&amp;=&amp;3K_{i+1}1^2-3C_{i,2}1^2+6C_{i,2}\left(1-1\right)1-6C_{i,1}\left(1-1\right)1+3C_{i,1}\left(1-1\right)^2-3K_i\left(1-1\right)^2\\<br />
&amp;=&amp;3K_{i+1}-3C_{i,2}+6C_{i,2}(0)1-6C_{i,1}(0)1+3C_{i,1}(0)^2-3K_i(0)^2\\<br />
&amp;=&amp;3K_{i+1}-3C_{i,2}.<br />
\end{eqnarray*}<br />
and evaluating $B_{i+1}^\prime(0)$ gives<br />
\begin{eqnarray*}<br />
B_{i+1}^\prime(0)&amp;=&amp;3K_{i+2}0^2-3C_{i+1,2}0^2+6C_{i+1,2}\left(1-0\right)0\\<br />
&amp;=&amp;-6C_{i+1,1}\left(1-0\right)0+3C_{i+1,1}\left(1-0\right)^2-3K_{i+1}\left(1-0\right)^2\\<br />
&amp;=&amp;3C_{i+1,1}-3K_{i+1}<br />
\end{eqnarray*}<br />
Therefore, for each $i$<br />
\begin{eqnarray*}<br />
B_i^\prime(1)&amp;=&amp;B_{i+1}^\prime(0)\\<br />
3K_{i+1}-3C_{i,2}&amp;=&amp;3C_{i+1,1}-3K_{i+1}\\<br />
6K_{i+1}&amp;=&amp;3C_{i,2}+3C_{i+1,1}\\<br />
K_{i+1}&amp;=&amp;0.5C_{i,2}+0.5C_{i+1,1}.<br />
\end{eqnarray*}</p>
<p>Evaluating $B_i^{\prime\prime}(1)$ gives<br />
\begin{eqnarray*}<br />
B_i^{\prime\prime}(1)&amp;=&amp;6 K_i (1 &#8211; t) + 6 C_{i,1} t  &#8211; 12 C_{i,1} (1 &#8211; t) &#8211; 12 C_{i,2} t  + 6 C_{i,2} (1 &#8211; t) + 6 K_{i+1} t\\<br />
&amp;=&amp;6K_i(0)+6C_{i,1}-12C_{i,1}(0)-12C_{i,2}+6C_{i,2}(0)+6K_{i+1}\\<br />
&amp;=&amp;6C_{i,1}-12C_{i,2}+6K_{i+1}\\<br />
\end{eqnarray*}<br />
and evaluating $B_{i+1}^{\prime\prime}(0)$ gives<br />
\begin{eqnarray*}<br />
B_{i+1}^{\prime\prime}(1)&amp;=&amp;6 K_{i+1} (1 &#8211; t) + 6 C_{i+1,1} t  &#8211; 12 C_{i+1,1} (1 &#8211; t) &#8211; 12 C_{i+1,2} t  + 6 C_{i+1,2} (1 &#8211; t) + 6 K_{i+2} t\\<br />
&amp;=&amp;6 K_{i+1} (1 &#8211; 0) + 6 C_{i+1,1} 0  &#8211; 12 C_{i+1,1} (1 &#8211; 0) &#8211; 12 C_{i+1,2} 0  + 6 C_{i+1,2} (1 &#8211; 0) + 6 K_{i+2} 0\\<br />
&amp;=&amp;6 K_{i+1} &#8211; 12 C_{i+1,1} + 6 C_{i+1,2}.<br />
\end{eqnarray*}<br />
Therefore, for each $i$<br />
\begin{eqnarray*}<br />
B_i^{\prime\prime}(1)&amp;=&amp;B_{i+1}^{\prime\prime}(0)\\<br />
6C_{i,1}-12C_{i,2}+6K_{i+1}&amp;=&amp;6 K_{i+1} &#8211; 12 C_{i+1,1} + 6 C_{i+1,2}\\<br />
0&amp;=&amp;-6C_{i,1}+12C_{i,2}-12 C_{i+1,1} + 6 C_{i+1,2}\\<br />
0&amp;=&amp;-C_{i,1}+2C_{i,2}-2 C_{i+1,1} + C_{i+1,2}\\<br />
\end{eqnarray*}</p>
<p>We now have $(2\times n-1)-2$ equations and $(2\times n-1)$ unknown control points.  We construct the linear system<br />
$$<br />
\left(<br />
\begin{array}{ccccccc}<br />
0&amp;0.5&amp;0.5&amp;0&amp;0&amp;0&amp;\ldots\\<br />
-1&amp;2&amp;-2&amp;1&amp;0&amp;0&amp;\ldots\\<br />
0&amp;0&amp;0&amp;0.5&amp;0.5&amp;0&amp;\ldots\\<br />
0&amp;0&amp;-1&amp;2&amp;-2&amp;1&amp;\ldots\\<br />
%0&amp;0&amp;0&amp;0.5&amp;0.5&amp;0&amp;\ldots\\<br />
%0&amp;0&amp;1&amp;-2&amp;2&amp;-1&amp;\ldots\\<br />
\vdots&amp;&amp;&amp;&amp;&amp;&amp;<br />
\end{array}<br />
\right)<br />
\times<br />
\left(<br />
\begin{array}{c}<br />
C_{0, 1}\\<br />
C_{0, 2}\\<br />
C_{1, 1}\\<br />
C_{1, 2}\\<br />
\ldots<br />
\end{array}<br />
\right)<br />
=<br />
\left(<br />
\begin{array}{c}<br />
K_1\\<br />
0\\<br />
K_2\\<br />
0\\<br />
\ldots<br />
\end{array}<br />
\right).<br />
$$</p>
<p>We also have the natural boundary conditions that $B^{\prime\prime}_0(0)=0$ and $B_{n-1}^{\prime\prime}(1)=0$.  The linear system then becomes<br />
$$<br />
\left(<br />
\begin{array}{ccccccccc}<br />
2&amp;-1&amp;0&amp;0&amp;0&amp;0&amp;\ldots&amp;0&amp;0\\<br />
0&amp;0.5&amp;0.5&amp;0&amp;0&amp;0&amp;\ldots&amp;0&amp;0\\<br />
-1&amp;2&amp;-2&amp;1&amp;0&amp;0&amp;\ldots&amp;0&amp;0\\<br />
0&amp;0&amp;0&amp;0.5&amp;0.5&amp;0&amp;\ldots&amp;0&amp;0\\<br />
0&amp;0&amp;-1&amp;2&amp;-2&amp;1&amp;\ldots&amp;0&amp;0\\<br />
%0&amp;0&amp;0&amp;0.5&amp;0.5&amp;0&amp;\ldots&amp;0&amp;0\\<br />
%0&amp;0&amp;1&amp;-2&amp;2&amp;-1&amp;\ldots&amp;0&amp;0\\<br />
\vdots&amp;&amp;&amp;&amp;&amp;&amp;&amp;&amp;\\<br />
0&amp;0&amp;0&amp;0&amp;0&amp;0&amp;\ldots&amp;-1&amp;2<br />
\end{array}<br />
\right)<br />
\times<br />
\left(<br />
\begin{array}{c}<br />
C_{0, 1}\\<br />
C_{0, 2}\\<br />
C_{1, 1}\\<br />
C_{1, 2}\\<br />
\ldots<br />
\end{array}<br />
\right)<br />
=<br />
\left(<br />
\begin{array}{c}<br />
0\\<br />
K_1\\<br />
0\\<br />
K_2\\<br />
0\\<br />
\ldots\\<br />
0<br />
\end{array}<br />
\right).<br />
$$</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.linux.ie/balor/2011/01/30/cubic-spline-interpolation/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

