<?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>Der Blog (mk II)</title>
	<atom:link href="http://sucs.org/~pwb/wordpress/feed/" rel="self" type="application/rss+xml" />
	<link>http://sucs.org/~pwb/wordpress</link>
	<description>Noch mehr, was den haarigen Kerl betrifft</description>
	<lastBuildDate>Wed, 01 Dec 2010 03:32:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>Translation from Coulsonese into English of selected portions of David Cameron&#8217;s &#8220;Before protesting, students need to get the facts straight&#8221;</title>
		<link>http://sucs.org/~pwb/wordpress/2010/12/translation-from-coulsonese-into-english-of-david-camerons-before-protesting-students-need-to-get-the-facts-straight/</link>
		<comments>http://sucs.org/~pwb/wordpress/2010/12/translation-from-coulsonese-into-english-of-david-camerons-before-protesting-students-need-to-get-the-facts-straight/#comments</comments>
		<pubDate>Wed, 01 Dec 2010 03:26:42 +0000</pubDate>
		<dc:creator>Pete</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://sucs.org/~pwb/wordpress/?p=168</guid>
		<description><![CDATA[(Original article at London Evening Standard.) Today, the protesters will be out again on the streets of London, marching against this Coalition&#8217;s plans for higher education. Banners will be waved, slogans chanted, placards hoisted. Of course these people have a right to protest. Who are all you people? Get off my lawn! But I also [...]]]></description>
			<content:encoded><![CDATA[	<p>(Original article at <a title="London Evening Standard: Before protesting, students need to get the facts straight" href="http://www.thisislondon.co.uk/standard/article-23902443-before-protesting-students-need-to-get-the-facts-straight.do">London Evening Standard</a>.)<br />
<blockquote>Today, the protesters will be out again on the streets of London, marching against this Coalition&#8217;s plans for higher education.</p>

	<p>Banners will be waved, slogans chanted, placards hoisted.</p>

	<p>Of course these people have a right to protest.</blockquote><br />
Who are all you people? Get off my lawn!<br />
<blockquote>But I also believe they have a responsibility to know the full facts about what they&#8217;re objecting to &#8212; and judging by the fury that&#8217;s been unleashed, there are a lot of misconceptions flying around.</blockquote><br />
At least that&#8217;s what Andy tells me.<br />
<blockquote>Unlike our predecessors we won&#8217;t patronise the public by pretending there&#8217;s a bottomless pit of money we can dig into. There isn&#8217;t, and that means difficult choices need to be made.</blockquote><br />
Which is why we&#8217;re stealing from the future in as many ways as we can, and even some we can&#8217;t. Aren&#8217;t we clever? And brave! And so modest!<br />
<blockquote>The public subsidy for higher education is massive &#8212; this year the Government will spend around &#163;5 billion on teaching costs in English higher education alone &#8212; and in the context of spending restraint it cannot be exempted from cuts.</blockquote><br />
I impress you with arguing points I already know you disagree with using the obvious and uncontroversial.<br />
<blockquote>A lot has been said in recent weeks about what is in the interests of students, but this government is also responsible for the interests of taxpayers &#8212; and at a time of real financial hardship, a time when we have no choice but to make cuts across public spending, I don&#8217;t believe it is right that we ask those on low incomes to pay taxes to prop up an unaffordable university funding system that they are not benefiting from directly.</blockquote><br />
I can&#8217;t see indirect benefits, therefore they are irrelevant. Tax avoidance is irrelevant too &#8212;&#160;if George does it, surely there can&#8217;t be anything wrong with it.<br />
<blockquote>The second thing protesters should know is that these reforms are vital to maintaining a world-class higher education system in this country.</blockquote><br />
The free market can&#8217;t produce a world-class education system. Everyone knows that. But now we have one, the invisible hand will make everything better and cheaper.<br />
<blockquote>A lot of the banners waved in Whitehall proclaim the importance of education, both to our economy and as an end in itself. I&#8217;m in whole-hearted agreement with them &#8212; but it serves no one to have underfunded universities with fraying resources and fading reputations. It damages our economy and it damages the prospects of students.</blockquote><br />
Okay, I admit, some indirect benefits are relevant. But anyway, I&#8217;m pretty sure a dozen or so rich universities and no poor ones should be enough to educate millions of young people. They&#8217;re the future, don&#8217;t you know.<br />
<blockquote>These reforms are going to drive up the quality of higher education, because when more funding flows directly from the student rather than from government, universities will be pressured to up their game in order to attract more students &#8212; improving teaching quality, offering real value for money and offering better student support.</blockquote><br />
For my next trick, I will pull &#163;5 billion out of this hat. Rumours of a secret tunnel to the Treasury under the table are completely unfounded. The money really will come from the students of the future!<br />
<blockquote>These plans will mean that, like anyone else going to university, they get the burden of upfront costs taken off their shoulders &#8212; and that way no one will be locked out of the opportunity university brings.</blockquote><br />
My daddy paid for my coke habit while I was at Brasenose. Why can&#8217;t yours?<br />
<blockquote>So this is a solution that is fair on the taxpayer in a time of financial anxiety. It&#8217;s fair on the student, who will get better teaching.</blockquote><br />
Speaking of coke, I am high as a kite.<br />
<blockquote>Our Coalition partners have had a lot of stick for supporting this policy but their opponents should understand this: responsible politics is not about peddling fantasy policies without looking at the price tag and pleasing any crowd you&#8217;re playing to.</blockquote><br />
We didn&#8217;t have a fully costed manifesto, but by golly we&#8217;re glad they did, because now we can blame <em>them</em> for this mess. Even though they tore it up as soon as we told them to.</p>
 ]]></content:encoded>
			<wfw:commentRss>http://sucs.org/~pwb/wordpress/2010/12/translation-from-coulsonese-into-english-of-david-camerons-before-protesting-students-need-to-get-the-facts-straight/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Excess packaging</title>
		<link>http://sucs.org/~pwb/wordpress/2009/03/excess-packaging/</link>
		<comments>http://sucs.org/~pwb/wordpress/2009/03/excess-packaging/#comments</comments>
		<pubDate>Wed, 11 Mar 2009 22:45:19 +0000</pubDate>
		<dc:creator>Pete</dc:creator>
				<category><![CDATA[diary]]></category>

		<guid isPermaLink="false">http://sucs.org/~pwb/wordpress/?p=117</guid>
		<description><![CDATA[I got a package from Dabs today: You'd think I must have ordered something pretty big, right? Think again: That's a desktop microphone and a USB sound card. If they'd packaged them correctly they could have just posted them through the letterbox! Thankfully this isn't as bad as Dez's package from Scan which filled a [...]]]></description>
			<content:encoded><![CDATA[<p>I got a package from Dabs today:</p>

<p><img class="aligncenter size-medium wp-image-123" title="bigbox" src="http://sucs.org/~pwb/wordpress/wp-content/uploads/2009/03/bigbox-300x225.jpg" alt="bigbox" width="300" height="225" /></p>
<div style="clear:both"/>
<p>You'd think I must have ordered something pretty big, right? Think again:</p>

<p><img class="aligncenter size-medium wp-image-124" title="emptybox" src="http://sucs.org/~pwb/wordpress/wp-content/uploads/2009/03/emptybox-300x225.jpg" alt="emptybox" width="300" height="225" /></p>
<div style="clear:both"/>
<p>That's a desktop microphone and a USB sound card. If they'd packaged them correctly they could have just posted them through the letterbox!</p>

<p>Thankfully this isn't as bad as <a href="https://sucs.org/Blogs/dez/entry/excess-packaging">Dez's package from Scan</a> which filled a box about that size with mostly bubble wrap, the payload being a 2GB SD card. But it still defies common sense.</p>]]></content:encoded>
			<wfw:commentRss>http://sucs.org/~pwb/wordpress/2009/03/excess-packaging/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What&#8217;s Twitter for?</title>
		<link>http://sucs.org/~pwb/wordpress/2009/02/whats-twitter-for/</link>
		<comments>http://sucs.org/~pwb/wordpress/2009/02/whats-twitter-for/#comments</comments>
		<pubDate>Wed, 25 Feb 2009 13:45:05 +0000</pubDate>
		<dc:creator>Pete</dc:creator>
				<category><![CDATA[computing]]></category>
		<category><![CDATA[diary]]></category>
		<category><![CDATA[meta]]></category>
		<category><![CDATA[thinking aloud]]></category>

		<guid isPermaLink="false">http://sucs.org/~pwb/wordpress/?p=109</guid>
		<description><![CDATA[Discounting the last week, my last blog post was on 24 October, then 3 July, then 18 April. Prior to that I was posting a couple of times a month. So what happened to my blog in 2008? I started using Twitter. Twitter has been getting some mainstream press lately, mostly though celebrities using it [...]]]></description>
			<content:encoded><![CDATA[<p>Discounting the last week, my last blog post was on 24 October, then 3 July, then 18 April. Prior to that I was posting a couple of times a month. So what happened to my blog in 2008?</p>

<p>I started using <a href="http://twitter.com">Twitter</a>.</p>

<p>Twitter has been getting some mainstream press lately, mostly though celebrities using it &mdash; especially Stephen Fry and Jonathan Ross. As with any new communication medium people are asking: what exactly is it good for? On the Twitter website the synopsis is: "What are you doing?" Well, that doesn't quite describe how I use it. Here's what I use it for.</p>

<p>I use Twitter for semi-realtime conversations.</p>

<p>It may have started out as "What are you doing?" but really, that's just the starting point. Sometimes you really do say what you're doing and if your friends find it interesting, they can comment on it. And not only what you're doing &mdash; what you're reading and thinking too. I made only two "QOTD" blog posts last year because I was using Twitter to point these out instead.</p>

<p>Using TwitterFox, which makes my followings instantly available, it's more immediate than a blog and its comments which you have to dive into a feed reader to follow. It's also more uniform than blogs-with-comments, in the sense that the original message and its replies have the same status &mdash; they are both just tweets, whereas a blog post is somehow more important than the comments attached to it.</p>

<p>But at the same time it's less immediate than, say, Milliways, or IM. There was a gaping hole between realtime chat and blogging in terms of immediacy and Twitter fills that gap, which I think is why it's so popular. Nobody really wants to know <a href="http://www.penny-arcade.com/comic/2008/4/23/">what you are doing every minute of the day</a> and of course letting them know can be dangerous. But it's for sparking discussion and carrying it on, in a way that's <em>in the present</em> yet not demanding that you pay constant attention.</p>]]></content:encoded>
			<wfw:commentRss>http://sucs.org/~pwb/wordpress/2009/02/whats-twitter-for/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Letter to Alan Williams re: Coroners and Justice Bill</title>
		<link>http://sucs.org/~pwb/wordpress/2009/02/letter-to-alan-williams-re-coroners-and-justice-bill/</link>
		<comments>http://sucs.org/~pwb/wordpress/2009/02/letter-to-alan-williams-re-coroners-and-justice-bill/#comments</comments>
		<pubDate>Sat, 21 Feb 2009 22:57:07 +0000</pubDate>
		<dc:creator>Pete</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://sucs.org/~pwb/wordpress/?p=96</guid>
		<description><![CDATA[On 19 January I sent the following letter to my MP via WriteToThem: Dear Alan Williams, It has come to my attention that a Bill is being pushed through Parliament, namely the Coroners and Justice Bill, containing a clause, namely clause 152, amending the Data Protection Act (DPA). This clause would create a new type [...]]]></description>
			<content:encoded><![CDATA[<p>On 19 January I sent the following letter to my MP via <a href="http://www.writetothem.com">WriteToThem</a>:</p>

<blockquote><p>Dear Alan Williams,</p>

<p>It has come to my attention that a Bill is being pushed through Parliament, namely the Coroners and Justice Bill, containing a clause, namely clause 152, amending the Data Protection Act (DPA). This clause would create a new type of order, Information Sharing Orders, which is explicitly a loophole in the data-sharing restrictions in the DPA that essentially render it meaningless.</p>

<p>Specifically, the extra clause 50B(1) enables department heads to relax or tighten any restriction on information sharing at its convenience. Given the Government's inexcusable losses of individuals' private records, for example its loss of CDs in the post containing the unencrypted details of millions of Child Benefit claimants, I no longer trust the government to keep my data private. I certainly cannot accept any law which would allow my data to be shared with anyone the Government chooses, which is what this amendment amounts to.</p>

<p>The added clause 50B(1)(d) also allows an Information Sharing Order that amounts to a gagging order, apparently without restriction. This makes moot the Prime Minister's decision the other day not to hold a vote on the Bill which would have enabled MPs to conceal their expenses, an issue on which I have already written to you in protest.</p>

<p>Of even more concern is clause 50B(2), which would allow the head of any Government department to create new summary offences by order. This makes a mockery of the rule of law and demonstrates the Government's contempt of it. If this bill passes intact, I shall have to emigrate as the UK will no longer be somewhere I can feel safe. In a liberal democracy the government should live in fear of its citizens, not the
other way around.</p>

<p>The Coroners and Justice Bill simply cannot pass as it is now. It must be amended to remove clause 152, or it will no longer be possible to call the United Kingdom a liberal democracy which values the rule of law.</p>

<p>Yours sincerely,</p>

<p>Peter Berry</p></blockquote>

<p>He forwarded the letter to Jack Straw, Lord Chancellor and Secretary of State for Justice, and got the following reply (written on 17 Feb), which he forwarded to me by post (on the 19th; it arrived today).</p>

<blockquote><p>Dear Alan, [handwritten]</p>

<p><b>MR PETER BERRY, [address redacted]</b></p>

<p>Thank you for your letter of 23 January on behalf of your constituent, Mr Peter Berry, who is concerned about the Coroners and Justice Bill, and in particular the Government's proposals to introduce new data sharing powers.</p>

<p>The proposal to introduce a power to create a new data sharing gateway stems from the recommendations of the Data Sharing Review, conducted independently by the Information Commissioner, Richard Thomas and Dr Mark Walport of the Wellcome Trust. The Review was commissioned by the Prime Minister in October 2007 to consider, amongst other things, how data sharing policy should be developed to ensure proper transparency, scrutiny and accountability. The Government believes it is vitally important that public trust in the handling of personal data must be maintained and the privacy of citizens protected. At the same time, data sharing between Government departments is essential in providing (and improving) customer-focussed public service delivery and also ensures individuals get the services they require. It is a matter of balance: whilst there are occasions where data sharing may not be appropriate (in order to protect individuals' privacy, for example), there are occasions where not sharing data may cause considerable harm.</p>

<p>The Data Sharing Review report was published on 11 July 2008 and included several recommendations for changes to the legal framework surrounding data sharing. The Review noted that while legal uncertainty and confusion are significant barriers to sharing, there have also been instances when legitimate data sharing schemes have been prevented due to legal obstacles.</p>

<p>In its response to the Review, published in November 2008, the Government broadly welcomed the report and agreed with the Review's recommendation to introduce a new statutory fast-track procedure for instances where there is a genuine case for removing or modifying an existing legal barrier to data sharing. The Government proposes to amend the DPA so that a statutory instrument procedure is created that will permit the sharing of personal information between persons or bodies, so long as a robust case can be made for the sharing to take place.</p>

<p>The sharing of personal data between Government departments in a secure and appropriate manner is essential to protect the public and to deliver public services. In recent years, data sharing has helped the most vulnerable in society, for example by identifying elderly people needing support with fuel payments, children who qualify for free school meals, and those eligible for assistance in switching over to digital television. The proposed data sharing gateway would assist with the continued delivery of the protection and services expected of Government, with the ability to respond more effectively to quickly changing situations. These could involve the detection of fraud and other forms of organised crime, or respond to health epidemics and natural disasters.</p>

<p>I understand Mr Berry's concerns and I assure him that the Government takes the protection of personal information seriously. Data sharing must be justifiable, proportionate and only undertaken when proper safeguards are in place.</p>

<p>Mr Berry may be reassured to know that the proposed new data sharing powers are combined with important safeguards. The Government plans to make any order wishing to use this new data sharing gateway subject to debate in both Houses of Parliament (through the affirmative resolution procedure), so that Parliament will have to apprive [sic] every proposal. In addition, every proposal to share personal information using this new gateway will be subject to scrutiny by the Information Commissioner. The Commissioner may report on whether he is satisfied that the sharing of information enabled by the order is necessary to secure a relevant policy objective, that the effect of the provision made by the order strikes a fair balance between the public interest and the interests of any person affected by it. Proposals must further be accompanied by a Privacy Impact Assessment (PIA). A PIA will describe the initiative and analyse the proposal's implications for privacy and data protection, as well as benefits for individuals and the general public. The Government believes these measures will ensure individuals' rights are fully maintained and protected.</p>

<p>The power to permit data sharing would be an exercise of a minister's functions and, as with all other such matters, remain judicially reviewable. Consequently the power must be exercised within the terms of Articles 6 and 8 of the European Convention on Human Rights. While the power is capable of providing a legal basis for sharing where common law confidentiality and public law would otherwise prohibit it, the proposed power is to be structured in such a way that exemptions from common law and public law prohibitions will only be possible where it is necessary, proportionate and an effective balance between the public interest and the private interest of those affected has been achieved. I appreciate concerns that protections afforded by other laws may be set aside, however these safeguards ensure that this will not occur. Protection of the private personal information of individuals is paramount and the proposed power will only be capable of being put into effect where this principle is fully respected.</p>

<p>I trust that this information is helpful and I enclose a copy of this letter for you to forward to Mr Berry, should you wish to do so.</p>

<p>Yours, [signature]<br /><b>JACK STRAW</b></p>
</blockquote>]]></content:encoded>
			<wfw:commentRss>http://sucs.org/~pwb/wordpress/2009/02/letter-to-alan-williams-re-coroners-and-justice-bill/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Parameterised monads</title>
		<link>http://sucs.org/~pwb/wordpress/2009/02/parameterised-monads/</link>
		<comments>http://sucs.org/~pwb/wordpress/2009/02/parameterised-monads/#comments</comments>
		<pubDate>Sun, 15 Feb 2009 20:51:14 +0000</pubDate>
		<dc:creator>Pete</dc:creator>
				<category><![CDATA[category theory]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[Haskell]]></category>

		<guid isPermaLink="false">http://sucs.org/~pwb/wordpress/?p=93</guid>
		<description><![CDATA[This post assumes some knowledge of Haskell, in particular what monads and monad transformers are. It's literate Haskell, which means you can load it into ghci directly (well, you'll probably have to convert HTML entities to plain text first, particularly &#38;gt; and &#38;lt;.) &#62; {-# LANGUAGE NoImplicitPrelude, MultiParamTypeClasses, FunctionalDependencies #-} &#62; {-# LANGUAGE FlexibleInstances, FlexibleContexts, [...]]]></description>
			<content:encoded><![CDATA[<p>This post assumes some knowledge of Haskell, in particular what monads and monad transformers are. It's literate Haskell, which means you can load it into <tt>ghci</tt> directly (well, you'll probably have to convert HTML entities to plain text first, particularly <tt>&amp;gt;</tt> and <tt>&amp;lt;</tt>.)</p>

<pre><pre>
&gt; {-# LANGUAGE NoImplicitPrelude, MultiParamTypeClasses, FunctionalDependencies #-}
&gt; {-# LANGUAGE FlexibleInstances, FlexibleContexts, UndecidableInstances #-}
&gt; 
&gt; import Prelude hiding (Monad (..))
&gt; import qualified Prelude as P
&gt; import Control.Monad.Trans
</pre></pre>

<p>On the Haskell blog circuit recently the notion of "parameterised monad" has been floating about, provoked by a new paper <a href="http://lambda-the-ultimate.org/node/3210">"Parameterized Notions of Computation"</a>. I'll refrain from explaining it myself, instead linking to <a href="http://blog.sigfpe.com/2009/02/beyond-monads.html">Dan Piponi's post on the topic</a>. If you don't already know what parameterised monads are, go and read that.</p>

<p>It seems that a module has already been written to encode parameterised modules and uploaded to Hackage: <a href="http://hackage.haskell.org/cgi-bin/hackage-scripts/package/monad-param"><tt>Control.Monad.Parameterized</tt></a> (package <tt>monad-param</tt>). It dates from before the current excitement (2007 and it's at version 0.0.2) so the concept is apparently not new. It does however take a somewhat different approach, one that's seemingly more general but also more cumbersome. The change in approach is explained in <a href="http://comonad.com/reader/2007/parameterized-monads-in-haskell/">a blog post by its author, Edward Kmett</a>. Here's what the "parameterized monad" class would look like if translated from the paper:</p>
<span id="more-93"></span>
<pre><code>
&gt; class PMonad m where
&gt;     returnP :: a -&gt; m p p a
&gt;     (&gt;&gt;&gt;=)  :: m p1 p2 a -&gt; (a -&gt; m p2 p3 b) -&gt; m p1 p3 b
</code></pre>

<p>As Piponi explains, if the Prelude monad is some kind of generalised monoid where <tt>return</tt> is the unit and <tt>(>>=)</tt> is the operation, this class is a kind of generalised category where <tt>returnP</tt> is the identity and <tt>(>>>=)</tt> is arrow composition. Notice that you can only compose two arrows if their 'input' and 'output' types match. Now clearly we can set <tt>p1</tt> = <tt>p2</tt> and then ordinary monads fall out as a special case:</p>

<pre><code>
&gt; -- newtype wrapper, with two phantom types to get the correct kind
&gt; -- (m :: * -&gt; *, UnparameterizedMonad m :: * -&gt; * -&gt; * -&gt; *)
&gt; newtype UnparameterizedMonad m p1 p2 a = UM { runUM :: m a }
&gt;
&gt; instance P.Monad m =&gt; PMonad (UnparameterizedMonad m) where
&gt;     returnP       = UM . P.return
&gt;     UM mx &gt;&gt;&gt;= f  = UM $ mx P.&gt;&gt;= (runUM . f)
</code></pre>

<p>(<tt>P.Monad</tt> means the Prelude's concept of monad, whereas <tt>PMonad</tt> means parameterised monad.) What we have in <tt>Control.Monad.Parameterized</tt> is something like the following:</p>

<pre><code>
&gt; class Return m where
&gt;     returnM :: a -&gt; m a
&gt;
&gt; class Fail m where
&gt;     fail :: String -&gt; m a
&gt;
&gt; class (Functor m, Functor m&#039;, Functor m&#039;&#039;) =&gt; Bind m m&#039; m&#039;&#039; | m m&#039; -&gt; m&#039;&#039; where
&gt;     (&gt;&gt;=) :: m a -&gt; (a -&gt; m&#039; b) -&gt; m&#039;&#039; b
&gt;     (&gt;&gt;)  :: m a -&gt; m&#039; b -&gt; m&#039;&#039; b
&gt;     x &gt;&gt; y = x &gt;&gt;= \_ -&gt; y
&gt;
&gt; class (Fail m, Return m, Bind m m m) =&gt; Monad m
&gt; instance (Fail m, Return m, Bind m m m) =&gt; Monad m
</code></pre>

<p>The last class basically says that Prelude monads are parameterised monads in which the parameter doesn't change:</p>

<pre><code>
instance P.Monad m =&gt; Return m where
&nbsp;&nbsp;&nbsp;&nbsp;returnM = P.return

instance P.Monad m =&gt; Fail m where
&nbsp;&nbsp;&nbsp;&nbsp;fail = P.fail

instance (Functor m, P.Monad m) =&gt; Bind m m m where
&nbsp;&nbsp;&nbsp;&nbsp;(&gt;&gt;=) = (P.&gt;&gt;=)
</code></pre>

<p>(Unfortunately we can't guarantee a <tt>Functor</tt> instance for every Prelude monad - a known failing of the current Prelude. We also comment these instances out because they overlap with others.) Of course the thing to notice immediately is that this class doesn't make the parameters explicit; instead, the parameters can be provided any which way. The motivating example is a version of the <tt>State</tt> monad in which the type of the state can change.</p>

<pre><code>
&gt; newtype State s1 s2 a = State { runState :: s1 -&gt; (a, s2) }
&gt;
&gt; instance Functor (State s1 s2) where
&gt;     fmap f (State trans) =
&gt;         State $ \s -&gt; case trans s of
&gt;             (x, s&#039;) -&gt; (f x, s&#039;)
&gt;
&gt; instance Return (State s s) where
&gt;     returnM x = State $ \s -&gt; (x, s)
&gt;
&gt; instance Fail (State s1 s2) where
&gt;     fail = error
&gt;
&gt; instance Bind (State s1 s2) (State s2 s3) (State s1 s3) where
&gt;     State trans &gt;&gt;= f =
&gt;         State $ \s -&gt; case trans s of
&gt;             (x, s&#039;) -&gt; case f x of
&gt;                 State trans&#039; -&gt; trans&#039; s&#039;
&gt;
&gt; instance PMonad State where
&gt;     (&gt;&gt;&gt;=) =  (&gt;&gt;=)
&gt;     returnP = returnM
</code></pre>

<p>What the more general setup provides is the ability to do things like this:</p>

<pre><code>
&gt; instance Bind (State (s,t) (s&#039;,t&#039;)) (State s&#039; s&#039;&#039;) (State (s,t) (s&#039;&#039;,t&#039;)) where
&gt;     State trans &gt;&gt;= f = State $ \s -&gt; case trans s of
&gt;         (x, (s&#039;,t&#039;)) -&gt; case runState (f x) s&#039; of
&gt;             (y, s&#039;&#039;) -&gt; (y, (s&#039;&#039;, t&#039;))
</code></pre>

<p>In this example, you can use a state transformer to change just one element of a paired state, without explicitly converting it. (Of course the usefulness of this is limited by only being able to do this on the left component - if you added one for the right as well, it would be ambiguous.) Another example:</p>

<pre><code>
&gt; newtype StateT s1 s2 m a = StateT { runStateT :: s1 -&gt; m (a,s2) }
&gt; instance (Functor m, Return m, Bind m m m) =&gt; Functor (StateT s1 s2 m) where
&gt;     fmap f (StateT trans) = StateT $ \s -&gt; do
&gt;         (x,s&#039;) &amp;lt;- trans s
&gt;         returnM (f x, s&#039;)
&gt;
&gt; instance Return IO where
&gt;     returnM = P.return
&gt; instance Bind IO IO IO where
&gt;     (&gt;&gt;=) = (P.&gt;&gt;=)
&gt;
&gt; instance Bind IO (State s1 s2) (StateT s1 s2 IO) where
&gt;     mx &gt;&gt;= f =
&gt;         StateT $ \s -&gt;
&gt;             mx P.&gt;&gt;= \x -&gt;
&gt;             case f x of
&gt;                 State trans -&gt; P.return (trans s)
</code></pre>

<p>So now you can have an expression like <tt>getContents >>= modify (map toUpper)</tt> and you automatically get a value in the transformer version of the second monad with the first monad as inner. Actually, even monad transformers become a special case in this framework:</p>

<pre><code>
&gt; newtype Trivial a = Trivial { runTrivial :: a }
&gt; instance Functor Trivial where fmap f (Trivial x) = Trivial (f x)
&gt;
&gt; instance (P.Monad m, Functor m, MonadTrans t, Functor (t m)) =&gt;
&gt;         Bind m Trivial (t m) where
&gt;     mx &gt;&gt;= f = lift (fmap (runTrivial . f) mx)
&gt;
&gt; lift&#039; :: (Functor m, Bind m Trivial m&#039;) =&gt; m a -&gt; m&#039; a
&gt; lift&#039; mx = mx &gt;&gt;= Trivial
&gt;
&gt; instance MonadTrans (StateT s s) where
&gt;     lift mx = StateT $ \s -&gt; mx P.&gt;&gt;= \x -&gt; P.return (x,s)
</code></pre>

<p><tt>lift'</tt> does the same as <tt>lift</tt>: notice that <tt>lift getContents</tt> and <tt>lift' getContents</tt> can both be instantiated to the type <tt>StateT s s IO String</tt>. (Semantically, they both perform the IO action and leave the state alone.) Monad transformers are just monads that can have some other monad bound to it on the left and are parameterised by that monad. Actually, <tt>lift'</tt> does more than <tt>lift</tt>: it generalises even generalised lifting functions like <tt>liftIO</tt>:</p>

<pre><code>
&gt; instance (P.Monad m, Bind IO Trivial m) =&gt; MonadIO m where
&gt;     liftIO = lift&#039;
</code></pre>

<p>There is one big drawback to this implementation of parameterised monads, namely that the type of <tt>returnM</tt> can't be inferred reliably:</p>

<pre><code>
*Main&gt; runState (returnM 1 &gt;&gt;= \x -&gt; returnM x) ()

&amp;lt;interactive&gt;:1:10:
&nbsp;&nbsp;&nbsp;&nbsp;No instance for (Bind m m&#039; (State () s2))
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;arising from a use of `&gt;&gt;=&#039; at &amp;lt;interactive&gt;:1:10-38
&nbsp;&nbsp;&nbsp;&nbsp;Possible fix:
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;add an instance declaration for (Bind m m&#039; (State () s2))
&nbsp;&nbsp;&nbsp;&nbsp;In the first argument of `runState&#039;, namely
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;`(returnM 1 &gt;&gt;= \ x -&gt; returnM x)&#039;
&nbsp;&nbsp;&nbsp;&nbsp;In the expression: runState (returnM 1 &gt;&gt;= \ x -&gt; returnM x) ()
&nbsp;&nbsp;&nbsp;&nbsp;In the definition of `it&#039;:
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;it = runState (returnM 1 &gt;&gt;= \ x -&gt; returnM x) ()
</code></pre>

<p>Compare this to explicitly parameterised monads:</p>

<pre><code>
*Main&gt; runState (returnP 1 &gt;&gt;&gt;= \x -&gt; returnP x) ()
(1,())
</code></pre>

<p>And normal monads:</p>

<pre><code>
Prelude Control.Monad.State&gt; runState (return 1 &gt;&gt;= \x -&gt; return x) ()
(1,())
</code></pre>

<p>The problem here is that <tt>State</tt> has two parameters and the type inferencer must fill them in, even though they're irrelevant, but it can't see what they must be because the second <tt>returnM</tt> could actually be in any monad.</p>

<p>This framework also has the following problem: the <tt>Bind</tt> class has two monads as arguments (plus the third that depends on the first two), so to get <i>n</i> monads to work together in all combinations that make sense, you'll need up to <i>n</i><sup>2</sup> instances. This looks like the start of a maintenance nightmare.</p>
]]></content:encoded>
			<wfw:commentRss>http://sucs.org/~pwb/wordpress/2009/02/parameterised-monads/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Milk</title>
		<link>http://sucs.org/~pwb/wordpress/2008/10/milk/</link>
		<comments>http://sucs.org/~pwb/wordpress/2008/10/milk/#comments</comments>
		<pubDate>Thu, 23 Oct 2008 21:05:40 +0000</pubDate>
		<dc:creator>Pete</dc:creator>
				<category><![CDATA[diary]]></category>

		<guid isPermaLink="false">http://sucs.org/~pwb/wordpress/?p=92</guid>
		<description><![CDATA[At home (Cowplain, Hampshire) my family has been getting milk delivered to the doorstep in 1-pint glass bottles basically forever. I don't remember a time when we usually bought milk from a shop/supermarket along with the rest of our food, though we have done it on occasion (usually on a Sunday, when Friday's milk wasn't [...]]]></description>
			<content:encoded><![CDATA[<p>At home (Cowplain, Hampshire) my family has been getting milk delivered to the doorstep in 1-pint glass bottles basically forever. I don't remember a time when we usually bought milk from a shop/supermarket along with the rest of our food, though we have done it on occasion (usually on a Sunday, when Friday's milk wasn't quite enough for the whole weekend and Monday morning before the milkman comes). Despite that, in the 4 or so years I've been living in Swansea (actually 5 years, but I was in Germany for the 3rd) I've bought my milk in plastic bottles of 2 or 4 litres from a shop.</p>
<p>This year, for a change, I'm living in what might be considered a household of more than one person, so we buy milk for 4 or 5 people at once. That needs to happen a couple of times a week, but it's a bit inconvenient to go shopping for 5 that frequently (we've only actually had two communal shopping trips since I moved in at the start of the month). Moreover, I really hate throwing away a 6 litre plastic bottle every week; glass bottles from the milkman, which get collected and reused, don't consume (much) oil in their manufacture and don't go into landfill, so are far more environmentally friendly. So I decided to set up milk deliveries. Observing our milk consumption before that point I decided we'd need about 3 pints on Monday and Wednesday and 5 on Friday (to cover the weekend). And the consensus was to get semi-skimmed. So on Friday morning a couple of weeks ago five pints of milk appeared on the doorstep.</p>
<p>Five pints of <em>skimmed</em> milk.</p>
<p>Well, sometimes that happens. The milkman might not have had 5 pints of semi-skimmed available when he got to my house. (Usually though you manage to get a pint or two of the right kind and the rest of something else.) So I put up with it, and we used the milk over the weekend.</p>
<p>On Monday, there appeared on the doorstep three pints of skimmed milk. And again on Wednesday, and another five pints on Friday. There was still a pint or two left over from Friday when we got Monday's milk, partly because skimmed isn't as nice as semi-skimmed so we didn't use as much, but also because it was starting to go off, despite being kept in the fridge and its best before date being Wednesday. (I've always thought skimmed milk tastes like it's started to go off even before you get it.) I checked the order on two occasions to make sure the order was actually for semi-skimmed (annoyingly you can't actually view your existing order on the Dairy Crest website) but still we kept getting skimmed, and it went off before it was supposed to.</p>
<p>This Monday I got the bill. Pricing on the Dairy Crest website for ordinary milk is "at current prices". Now I found out that it costs 58p per pint, about twice as much as getting it from Tesco. I expected it would be more expensive since they have to deliver it, but for stuff that doesn't taste nice and goes off prematurely so we end up throwing half of it away, that's just not acceptable. So today I cancelled the order.</p>
<p>So this little experiment lasted about two and a half weeks, and was thoroughly unsatisfactory. A crying shame. Surely the milkmen in Uplands can't be <em>that</em> much less competent than the ones in Cowplain?</p>
]]></content:encoded>
			<wfw:commentRss>http://sucs.org/~pwb/wordpress/2008/10/milk/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Don&#8217;t trust US companies with your data</title>
		<link>http://sucs.org/~pwb/wordpress/2008/07/91/</link>
		<comments>http://sucs.org/~pwb/wordpress/2008/07/91/#comments</comments>
		<pubDate>Thu, 03 Jul 2008 16:17:24 +0000</pubDate>
		<dc:creator>Pete</dc:creator>
				<category><![CDATA[legal]]></category>
		<category><![CDATA[news]]></category>
		<category><![CDATA[rant]]></category>

		<guid isPermaLink="false">http://sucs.org/~pwb/wordpress/?p=91</guid>
		<description><![CDATA[We all know the USA badly needs some sane data protection legislation, and this is a good illustration of why: Yesterday, in the Viacom v. Google litigation, the federal court for the Southern District of New York ordered Google to produce to Viacom (over Google&#8217;s objections): all data from the Logging database concerning each time [...]]]></description>
			<content:encoded><![CDATA[	<p>We all know the <span class="caps">USA</span> badly needs some sane data protection legislation, and <a href="http://www.eff.org/deeplinks/2008/07/court-ruling-will-expose-viewing-habits-youtube-us" title="Court Ruling Will Expose Viewing Habits of YouTube Users">this</a> is a good illustration of why:<br />
<blockquote>Yesterday, in the <em>Viacom v. Google</em> litigation, the federal court for the Southern District of New York ordered Google to produce to Viacom (over Google&#8217;s objections):<br />
<blockquote>all data from the Logging database concerning each time a YouTube video has been viewed on the YouTube website or through embedding on a third-party website</blockquote><br />
The court&#8217;s order grants Viacom&#8217;s request and erroneously ignores the protections of the federal Video Privacy Protection Act (VPPA), and threatens to expose deeply private information about what videos are watched by YouTube users. The <span class="caps">VPPA</span> passed after a newspaper disclosed Supreme Court nominee Robert Bork&#8217;s video rental records. As Congress recognized, your selection of videos to watch is deeply personal and deserves the strongest protection.</blockquote><br />
(Fortunately this ruling appears to be illegal, but you can easily imagine that less-rich companies couldn&#8217;t afford to appeal.) Time to log out of YouTube and <a href="http://www.instructables.com/id/Go-Online-without-Getting-Snooped-Tor-The-Onion-/" title="Instructables: Go Online without Getting Snooped: Tor (The Onion Router)">start using Tor</a>.</p>
 ]]></content:encoded>
			<wfw:commentRss>http://sucs.org/~pwb/wordpress/2008/07/91/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>QOTD XVIII</title>
		<link>http://sucs.org/~pwb/wordpress/2008/04/qotd-xviii/</link>
		<comments>http://sucs.org/~pwb/wordpress/2008/04/qotd-xviii/#comments</comments>
		<pubDate>Fri, 18 Apr 2008 12:24:53 +0000</pubDate>
		<dc:creator>Pete</dc:creator>
				<category><![CDATA[language]]></category>
		<category><![CDATA[politics]]></category>
		<category><![CDATA[QOTD]]></category>

		<guid isPermaLink="false">http://sucs.org/~pwb/wordpress/?p=90</guid>
		<description><![CDATA[I have always been of the mind that when you visit a foreign country you&#8217;re the one that should make the effort to communicate with the locals. Speaking your birth tongue slower and louder doesn&#8217;t make yourself any more understandable, it just makes you look like a jackass. The onus to learn the local language [...]]]></description>
			<content:encoded><![CDATA[
	<p><blockquote><p>I have always been of the mind that when you visit a foreign country you&#8217;re the one that should make the effort to communicate with the locals. Speaking your birth tongue slower and louder doesn&#8217;t make yourself any more understandable, it just makes you look like a jackass. The onus to learn the local language is even heavier if you&#8217;re an immigrant. After all, you&#8217;re the one asking for the privilege of becoming a part of <em>someone else&#8217;s community.</em> That means you can bloody well learn the language; you don&#8217;t even have to succeed, you just have to show that you&#8217;re willing to <em>try.</em></p></blockquote>&#8212;- <a href="http://ars.userfriendly.org/news/?id=1208466459" title="[Illiad] OPINIONATED NEWS ITEM: HOLDING MULTICULTURALISM HOSTAGE">Illiad</a> (author of the webcomic UserFriendly). The subtitle is &#8220;Not multiculturalism, but covert colonialism&#8221;, the idea being that (for example) a Chinatown in Vancouver where nobody speaks English is a <em>colony</em>, in the worst sense of the word. Perhaps not everyone is interested in learning a language for its own sake like I would be (the only reason I don&#8217;t learn more languages is lack of time), but when the language is entrenched, not making the effort to learn it is simply rude.</p>
 ]]></content:encoded>
			<wfw:commentRss>http://sucs.org/~pwb/wordpress/2008/04/qotd-xviii/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Death of a giant</title>
		<link>http://sucs.org/~pwb/wordpress/2008/03/death-of-a-giant/</link>
		<comments>http://sucs.org/~pwb/wordpress/2008/03/death-of-a-giant/#comments</comments>
		<pubDate>Fri, 21 Mar 2008 00:43:03 +0000</pubDate>
		<dc:creator>Pete</dc:creator>
				<category><![CDATA[news]]></category>

		<guid isPermaLink="false">http://sucs.org/~pwb/wordpress/?p=89</guid>
		<description><![CDATA[Arthur C. Clarke died yesterday (OK, the day before yesterday) at the grand old age of 90. One of the last of the Golden Age writers, one of the best and most foresighted, and probably the most optimistic. He will be missed.]]></description>
			<content:encoded><![CDATA[	<p><p><a href="http://news.bbc.co.uk/2/hi/uk_news/7304004.stm" title="BBC News: Writer Arthur C Clarke dies at 90">Arthur C. Clarke died yesterday</a> (OK, the day before yesterday) at the grand old age of 90.</p><br />
<p>One of the last of the Golden Age writers, one of the best and most foresighted, and probably the most optimistic. He will be missed.</p></p>

 ]]></content:encoded>
			<wfw:commentRss>http://sucs.org/~pwb/wordpress/2008/03/death-of-a-giant/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Static typing and correctness</title>
		<link>http://sucs.org/~pwb/wordpress/2008/03/static-typing-and-correctness/</link>
		<comments>http://sucs.org/~pwb/wordpress/2008/03/static-typing-and-correctness/#comments</comments>
		<pubDate>Wed, 19 Mar 2008 21:52:28 +0000</pubDate>
		<dc:creator>Pete</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[computing]]></category>
		<category><![CDATA[thinking aloud]]></category>

		<guid isPermaLink="false">http://sucs.org/~pwb/wordpress/?p=88</guid>
		<description><![CDATA[I've been pointed to a post by Joel Spolsky advocating Hungarian notation so that code that fails to properly sanitise strings "looks wrong". Here's Joel's example. The idea is that you prefix the names of all string variables and functions returning strings with either "s" or "us" depending on whether they're safe or unsafe respectively. [...]]]></description>
			<content:encoded><![CDATA[<p>I've been pointed to <a href="http://www.joelonsoftware.com/articles/Wrong.html" title="Joel on Software: Making Wrong Code Look Wrong">a post by Joel Spolsky</a> advocating <a href="http://en.wikipedia.org/wiki/Hungarian_notation">Hungarian notation</a> so that code that fails to properly sanitise strings "looks wrong".</p>
<p>Here's Joel's example. The idea is that you prefix the names of all string variables and functions returning strings with either "s" or "us" depending on whether they're safe or unsafe respectively. Then assignments that have "s" on one side and "us" on the other just look wrong.</p>
<blockquote class="noquote"><pre><code>us = UsRequest(&quot;name&quot;) // ok, both sides start with US
s = UsRequest(&quot;name&quot;) // bug
usName = us // ok
sName = us // certainly wrong.
sName = SEncode(us) // certainly correct.
</code></pre></blockquote>
<p>Well I can think of one pitfall already. How do you mark whether a function expects safe or unsafe data in a way that makes wrong code look wrong?</p>
<blockquote class="noquote"><pre><code>us = UsRequest(&quot;name&quot;) // okay
RandomMangler(s) // okay
RandomMangler(us) // errm... wrong?</code></pre></blockquote>
<p><!-- more --></p>
<p>If you're using a language that supports it, there is a far better way.<span id="more-88"></span> Think about it. What does Hungarian notation do? It marks the fact that a variable contains data that statically has some property (that is, we know it has that property at compile time). What else can you think of that tells you about static properties of data? What, for example, do we know about any random string? We know it is a string, and that's about it. But that gives us a clue. In most languages a string has some type that marks it as a string. If it's not a string, it can't have that type. What if we made sure that if a string isn't safe, it can't have some type?</p>
<blockquote class="noquote"><pre><code>class SafeString extends String {
&nbsp;&nbsp;&nbsp;&nbsp;public static SafeString sanitize(String s) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;... // sanitise it
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return new SafeString(s);
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;private SafeString(String stock) { return new String(stock); }
&nbsp;&nbsp;&nbsp;&nbsp;...
}
</code></pre></blockquote>
<p>Now we can have something that is still a string (SafeString is a subtype of String), but if we want something that only accepts safe strings we can give its argument the type SafeString. Then because the only way we can create a safe string is by sanitising it first, we can never pass an unsafe string to something needing a safe one. To put it another way, wrong code now looks wrong <em>to the compiler</em>. And the compiler is much, much better at spotting things that look wrong than you are:</p>
<blockquote class="noquote"><pre><code>us = Request(&quot;name&quot;) // ok
s = Request(&quot;name&quot;) // type error
usName = us // ok
sName = us // type error
sName = SafeString.sanitize(us) // ok
</code></pre></blockquote>
<p>These type errors will produce a compile time error -- the code simply won't compile, so it can't cause security problems, because it never becomes an executable program. Of course, this only works if your language is strongly, statically typed -- if it isn't, you still get binaries that either break (because the typing is weak, so you can pass unsafe strings to things expecting safe ones and it still compiles) or blow up (because the typing is dynamic, so passing unsafe strings to functions expecting safe ones causes a runtime error). You might consider runtime errors to be bad or not, depending on your perspective, but letting type errors slide is to be avoided.</p>
]]></content:encoded>
			<wfw:commentRss>http://sucs.org/~pwb/wordpress/2008/03/static-typing-and-correctness/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
