<?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"
	>

<channel>
	<title>λ Tony’s blog λ</title>
	<atom:link href="http://blog.tmorris.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.tmorris.net</link>
	<description>The weblog of Tony Morris</description>
	<pubDate>Wed, 10 Mar 2010 02:36:21 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6</generator>
	<language>en</language>
			<item>
		<title>What Really Happened</title>
		<link>http://blog.tmorris.net/what-really-happened/</link>
		<comments>http://blog.tmorris.net/what-really-happened/#comments</comments>
		<pubDate>Tue, 09 Mar 2010 06:03:57 +0000</pubDate>
		<dc:creator>Tony Morris</dc:creator>
		
		<category><![CDATA[Health]]></category>

		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.tmorris.net/?p=661</guid>
		<description><![CDATA[
28 July 2007 Ankle inversion sprain resulting in entrapment neuropathy of the superficial peroneal nerve 10 cm proximal to lateral malleolus. Continued athletic activity causes minor avulsions at the nerve root (L5/S1).
15 September 2008 Surgical ligament repair, inadvertently putting further traction on the trapped superficial peroneal nerve. Avulsion of the nerve root completed. CSF leaks [...]]]></description>
			<content:encoded><![CDATA[<ul>
<li><strong>28 July 2007</strong> Ankle inversion sprain resulting in entrapment neuropathy of the superficial peroneal nerve 10 cm proximal to lateral malleolus. Continued athletic activity causes minor avulsions at the nerve root (L5/S1).</li>
<li><strong>15 September 2008</strong> Surgical ligament repair, inadvertently putting further traction on the trapped superficial peroneal nerve. Avulsion of the nerve root completed. CSF leaks from the spinal cord into surrounding tissues. Psychiatric symptoms develop.</li>
<li><strong>04 November 2009</strong> Surgical decompression of superficial peroneal nerve provides relief.</li>
<li><strong>Today</strong> spinal injury. Lumbosacral Nerve Root Avulsion.</li>
</ul>
<p>I have a spinal injury as a result of an otherwise innocent ankle sprain. This is due to the extreme negligence of medical practitioners. Dr Michael McEniery and Dr Rupert Leigh Atkinson are extremely dangerous people who should not be practicing medicine in any form. These people, who hold medical treatment hostage behind a barrier of extreme incompetence of the highest order, are the biggest threat to the safety of the general public that I have ever encountered (and I&#8217;ve visited a maximum security prison).</p>
<p>Next time I scream, please listen. You all heard me didn&#8217;t you?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tmorris.net/what-really-happened/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Why are there no big applications written using functional languages?</title>
		<link>http://blog.tmorris.net/why-are-there-no-big-applications-written-using-functional-languages/</link>
		<comments>http://blog.tmorris.net/why-are-there-no-big-applications-written-using-functional-languages/#comments</comments>
		<pubDate>Wed, 24 Feb 2010 12:02:33 +0000</pubDate>
		<dc:creator>Tony Morris</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.tmorris.net/?p=658</guid>
		<description><![CDATA[Because there is no such thing as a big application. There is only bigger or smaller. This is a central tenet of functional programming. &#8220;Big application&#8221; is a euphemism for &#8220;My idea of programming does not scale beyond this point.&#8221; You don&#8217;t realise how much information you give away when you ask this question.
So can [...]]]></description>
			<content:encoded><![CDATA[<p>Because there is no such thing as a big application. There is only bigger or smaller. This is a central tenet of functional programming. &#8220;Big application&#8221; is a euphemism for &#8220;My idea of programming does not scale beyond this point.&#8221; You don&#8217;t realise how much information you give away when you ask this question.</p>
<p>So can we can stop with the piffle and get on with the interesting and important stuff? Ta.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tmorris.net/why-are-there-no-big-applications-written-using-functional-languages/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Understanding Haskell interact</title>
		<link>http://blog.tmorris.net/understanding-haskell-interact/</link>
		<comments>http://blog.tmorris.net/understanding-haskell-interact/#comments</comments>
		<pubDate>Tue, 23 Feb 2010 23:01:04 +0000</pubDate>
		<dc:creator>Tony Morris</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.tmorris.net/?p=655</guid>
		<description><![CDATA[There is a function in Haskell&#8217;s standard library called interact. It has this type interact :: (String -> String) -> IO ().
Here is the same function in Java:

import java.io.Console;
&#160;
interface Stringer &#123;
  String convertString&#40;String s&#41;;
&#125;
&#160;
class Interact &#123;
  // interact :: (String -&#62; String) -&#62; IO ()
  static void interact&#40;Stringer s&#41; &#123;
   [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v%3Ainteract" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.haskell.org');">There is a function</a> in Haskell&#8217;s standard library called interact. It has this type <code>interact :: (String -> String) -> IO ()</code>.</p>
<p>Here is the same function in Java:</p>

<div class="wp_syntax"><div class="code"><pre class="java"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.Console</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">interface</span> Stringer <span style="color: #009900;">&#123;</span>
  <span style="color: #003399;">String</span> convertString<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> s<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> Interact <span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// interact :: (String -&gt; String) -&gt; IO ()</span>
  <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> interact<span style="color: #009900;">&#40;</span>Stringer s<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> line <span style="color: #339933;">=</span> <span style="color: #003399;">System</span>.<span style="color: #006633;">console</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">readLine</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> c <span style="color: #339933;">=</span> s.<span style="color: #006633;">convertString</span><span style="color: #009900;">&#40;</span>line<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>c<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    interact<span style="color: #009900;">&#40;</span>s<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>There are some slight differences between the two:</p>
<ul>
<li>In Java, we have had to give a name to the higher-order function (<code>Stringer</code>) with a single method which we have also named (<code>convertString</code>).</li>
<li>In Java, we have no guarantee that the implementation of <code>Stringer</code> that is passed to <code>interact</code> is deterministic. In other words, it might perform side-effects and we have no machine-checked guarantee that it will not.</code></li>
</ul>
<p>The other major difference is with respect to the evaluation of the arguments. Haskell is call-by-need by default while Java is eagerly evaluated by force. This doesn&#8217;t have an impact on understanding the general purpose of Haskell&#8217;s <code>interact</code> function by looking at the same function in Java.</p>
<p>That is all. Hope it helps.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tmorris.net/understanding-haskell-interact/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Linq has nothing to do with SQL or enumerable lists</title>
		<link>http://blog.tmorris.net/linq-has-nothing-to-do-with-sql-or-enumerable-lists/</link>
		<comments>http://blog.tmorris.net/linq-has-nothing-to-do-with-sql-or-enumerable-lists/#comments</comments>
		<pubDate>Fri, 19 Feb 2010 00:43:43 +0000</pubDate>
		<dc:creator>Tony Morris</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.tmorris.net/?p=653</guid>
		<description><![CDATA[There seems to be quite a lot of misunderstanding of Linq. I am not sure how widespread this misunderstanding is, but if I can be persuaded that my selection sample extrapolates accurately, I might consider expanding on this fact:

Linq has nothing to do with SQL or enumerable lists. Nothing and also, not a single thing.

If [...]]]></description>
			<content:encoded><![CDATA[<p>There seems to be quite a lot of misunderstanding of Linq. I am not sure how widespread this misunderstanding is, but if I can be persuaded that my selection sample extrapolates accurately, I might consider expanding on this fact:</p>
<blockquote><p>
Linq has nothing to do with SQL or enumerable lists. Nothing and also, not a single thing.
</p></blockquote>
<p>If this is contentious, please let me know and I will endeavour to do something about it (I already have, so I&#8217;ll just refer on to begin with).</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tmorris.net/linq-has-nothing-to-do-with-sql-or-enumerable-lists/feed/</wfw:commentRss>
		</item>
		<item>
		<title>SKI combinator calculus in Java</title>
		<link>http://blog.tmorris.net/ski-combinator-calculus-in-java/</link>
		<comments>http://blog.tmorris.net/ski-combinator-calculus-in-java/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 07:17:57 +0000</pubDate>
		<dc:creator>Tony Morris</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.tmorris.net/?p=651</guid>
		<description><![CDATA[
interface Lam&#60;X, Y&#62; &#123;
  Y apply&#40;X x&#41;;
&#125;
&#160;
// http://en.wikipedia.org/wiki/SKI_combinator_calculus
class SKI &#123;
  public static &#60;A, B, C&#62; Lam&#60;Lam&#60;A, Lam&#60;B, C&#62;&#62;, Lam&#60;Lam&#60;A, B&#62;, Lam&#60;A, C&#62;&#62;&#62; s&#40;&#41; &#123;
    return new Lam&#60;Lam&#60;A, Lam&#60;B, C&#62;&#62;, Lam&#60;Lam&#60;A, B&#62;, Lam&#60;A, C&#62;&#62;&#62;&#40;&#41; &#123;
      public Lam&#60;Lam&#60;A, B&#62;, Lam&#60;A, C&#62;&#62; apply&#40;final Lam&#60;A, Lam&#60;B, C&#62;&#62; f&#41; &#123;
 [...]]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="java"><span style="color: #000000; font-weight: bold;">interface</span> Lam<span style="color: #339933;">&lt;</span>X, Y<span style="color: #339933;">&gt;</span> <span style="color: #009900;">&#123;</span>
  Y apply<span style="color: #009900;">&#40;</span>X x<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// http://en.wikipedia.org/wiki/SKI_combinator_calculus</span>
<span style="color: #000000; font-weight: bold;">class</span> SKI <span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #339933;">&lt;</span>A, B, C<span style="color: #339933;">&gt;</span> Lam<span style="color: #339933;">&lt;</span>Lam<span style="color: #339933;">&lt;</span>A, Lam<span style="color: #339933;">&lt;</span>B, C<span style="color: #339933;">&gt;&gt;</span>, Lam<span style="color: #339933;">&lt;</span>Lam<span style="color: #339933;">&lt;</span>A, B<span style="color: #339933;">&gt;</span>, Lam<span style="color: #339933;">&lt;</span>A, C<span style="color: #339933;">&gt;&gt;&gt;</span> s<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> Lam<span style="color: #339933;">&lt;</span>Lam<span style="color: #339933;">&lt;</span>A, Lam<span style="color: #339933;">&lt;</span>B, C<span style="color: #339933;">&gt;&gt;</span>, Lam<span style="color: #339933;">&lt;</span>Lam<span style="color: #339933;">&lt;</span>A, B<span style="color: #339933;">&gt;</span>, Lam<span style="color: #339933;">&lt;</span>A, C<span style="color: #339933;">&gt;&gt;&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">public</span> Lam<span style="color: #339933;">&lt;</span>Lam<span style="color: #339933;">&lt;</span>A, B<span style="color: #339933;">&gt;</span>, Lam<span style="color: #339933;">&lt;</span>A, C<span style="color: #339933;">&gt;&gt;</span> apply<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> Lam<span style="color: #339933;">&lt;</span>A, Lam<span style="color: #339933;">&lt;</span>B, C<span style="color: #339933;">&gt;&gt;</span> f<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> Lam<span style="color: #339933;">&lt;</span>Lam<span style="color: #339933;">&lt;</span>A, B<span style="color: #339933;">&gt;</span>, Lam<span style="color: #339933;">&lt;</span>A, C<span style="color: #339933;">&gt;&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
          <span style="color: #000000; font-weight: bold;">public</span> Lam<span style="color: #339933;">&lt;</span>A, C<span style="color: #339933;">&gt;</span> apply<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> Lam<span style="color: #339933;">&lt;</span>A, B<span style="color: #339933;">&gt;</span> g<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> Lam<span style="color: #339933;">&lt;</span>A, C<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
              <span style="color: #000000; font-weight: bold;">public</span> C apply<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> A a<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000000; font-weight: bold;">return</span> f.<span style="color: #006633;">apply</span><span style="color: #009900;">&#40;</span>a<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">apply</span><span style="color: #009900;">&#40;</span>g.<span style="color: #006633;">apply</span><span style="color: #009900;">&#40;</span>a<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
              <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
          <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #339933;">&lt;</span>A, B<span style="color: #339933;">&gt;</span> Lam<span style="color: #339933;">&lt;</span>A, Lam<span style="color: #339933;">&lt;</span>B, A<span style="color: #339933;">&gt;&gt;</span> k<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> Lam<span style="color: #339933;">&lt;</span>A, Lam<span style="color: #339933;">&lt;</span>B, A<span style="color: #339933;">&gt;&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">public</span> Lam<span style="color: #339933;">&lt;</span>B, A<span style="color: #339933;">&gt;</span> apply<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> A a<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> Lam<span style="color: #339933;">&lt;</span>B, A<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
          <span style="color: #000000; font-weight: bold;">public</span> A apply<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> B b<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">return</span> a<span style="color: #339933;">;</span>
          <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #339933;">&lt;</span>A<span style="color: #339933;">&gt;</span> Lam<span style="color: #339933;">&lt;</span>A, A<span style="color: #339933;">&gt;</span> i<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">return</span> SKI.<span style="color: #339933;">&lt;</span>A, Lam<span style="color: #339933;">&lt;</span>A, A<span style="color: #339933;">&gt;</span>, A<span style="color: #339933;">&gt;</span>s<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">apply</span><span style="color: #009900;">&#40;</span>SKI.<span style="color: #339933;">&lt;</span>A, Lam<span style="color: #339933;">&lt;</span>A, A<span style="color: #339933;">&gt;&gt;</span>k<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">apply</span><span style="color: #009900;">&#40;</span>SKI.<span style="color: #339933;">&lt;</span>A, A<span style="color: #339933;">&gt;</span>k<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.tmorris.net/ski-combinator-calculus-in-java/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Scala exercise</title>
		<link>http://blog.tmorris.net/scala-exercise/</link>
		<comments>http://blog.tmorris.net/scala-exercise/#comments</comments>
		<pubDate>Fri, 05 Feb 2010 23:37:10 +0000</pubDate>
		<dc:creator>Tony Morris</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.tmorris.net/?p=649</guid>
		<description><![CDATA[A result of a discussion in the #scala IRC channel.
Write a minimum function that works on Array[String] and List[Int]. (see error("todo"))

trait Foldable&#91;-F&#91;_&#93;&#93; &#123;
  def foldl&#91;A, B&#93;&#40;f: &#40;A, B&#41; =&#62; A, a: A, as: F&#91;B&#93;&#41;: A
&#160;
  def reducel&#91;A&#93;&#40;f: &#40;A, A&#41; =&#62; A, as: F&#91;A&#93;&#41;: Option&#91;A&#93; = foldl&#91;Option&#91;A&#93;, A&#93;&#40;&#40;a1, a2&#41; =&#62; 
    [...]]]></description>
			<content:encoded><![CDATA[<p>A result of a discussion in the <a href="irc://freenode.net/#scala" onclick="javascript:pageTracker._trackPageview('/outbound/article/freenode.net');">#scala IRC channel</a>.</p>
<p><strong>Write a minimum function that works on <code>Array[String]</code> and <code>List[Int]</code>.</strong> <em>(see <code>error("todo")</code>)</em></p>

<div class="wp_syntax"><div class="code"><pre class="scala"><span style="color: #0000ff; font-weight: bold;">trait</span> Foldable<span style="color: #F78811;">&#91;</span>-F<span style="color: #F78811;">&#91;</span><span style="color: #000080;">_</span><span style="color: #F78811;">&#93;</span><span style="color: #F78811;">&#93;</span> <span style="color: #F78811;">&#123;</span>
  <span style="color: #0000ff; font-weight: bold;">def</span> foldl<span style="color: #F78811;">&#91;</span>A, B<span style="color: #F78811;">&#93;</span><span style="color: #F78811;">&#40;</span>f<span style="color: #000080;">:</span> <span style="color: #F78811;">&#40;</span>A, B<span style="color: #F78811;">&#41;</span> <span style="color: #000080;">=&gt;</span> A, a<span style="color: #000080;">:</span> A, as<span style="color: #000080;">:</span> F<span style="color: #F78811;">&#91;</span>B<span style="color: #F78811;">&#93;</span><span style="color: #F78811;">&#41;</span><span style="color: #000080;">:</span> A
&nbsp;
  <span style="color: #0000ff; font-weight: bold;">def</span> reducel<span style="color: #F78811;">&#91;</span>A<span style="color: #F78811;">&#93;</span><span style="color: #F78811;">&#40;</span>f<span style="color: #000080;">:</span> <span style="color: #F78811;">&#40;</span>A, A<span style="color: #F78811;">&#41;</span> <span style="color: #000080;">=&gt;</span> A, as<span style="color: #000080;">:</span> F<span style="color: #F78811;">&#91;</span>A<span style="color: #F78811;">&#93;</span><span style="color: #F78811;">&#41;</span><span style="color: #000080;">:</span> Option<span style="color: #F78811;">&#91;</span>A<span style="color: #F78811;">&#93;</span> <span style="color: #000080;">=</span> foldl<span style="color: #F78811;">&#91;</span>Option<span style="color: #F78811;">&#91;</span>A<span style="color: #F78811;">&#93;</span>, A<span style="color: #F78811;">&#93;</span><span style="color: #F78811;">&#40;</span><span style="color: #F78811;">&#40;</span>a1, a2<span style="color: #F78811;">&#41;</span> <span style="color: #000080;">=&gt;</span> 
    Some<span style="color: #F78811;">&#40;</span>a1 <span style="color: #0000ff; font-weight: bold;">match</span> <span style="color: #F78811;">&#123;</span>
      <span style="color: #0000ff; font-weight: bold;">case</span> None <span style="color: #000080;">=&gt;</span> a2
      <span style="color: #0000ff; font-weight: bold;">case</span> Some<span style="color: #F78811;">&#40;</span>x<span style="color: #F78811;">&#41;</span> <span style="color: #000080;">=&gt;</span> f<span style="color: #F78811;">&#40;</span>a2, x<span style="color: #F78811;">&#41;</span>
    <span style="color: #F78811;">&#125;</span><span style="color: #F78811;">&#41;</span>, None, as<span style="color: #F78811;">&#41;</span>
<span style="color: #F78811;">&#125;</span>
&nbsp;
<span style="color: #0000ff; font-weight: bold;">object</span> Foldable <span style="color: #F78811;">&#123;</span>
  <span style="color: #0000ff; font-weight: bold;">val</span> ListFoldable <span style="color: #000080;">=</span> <span style="color: #0000ff; font-weight: bold;">new</span> Foldable<span style="color: #F78811;">&#91;</span>List<span style="color: #F78811;">&#93;</span> <span style="color: #F78811;">&#123;</span>
    <span style="color: #0000ff; font-weight: bold;">def</span> foldl<span style="color: #F78811;">&#91;</span>A, B<span style="color: #F78811;">&#93;</span><span style="color: #F78811;">&#40;</span>f<span style="color: #000080;">:</span> <span style="color: #F78811;">&#40;</span>A, B<span style="color: #F78811;">&#41;</span> <span style="color: #000080;">=&gt;</span> A, a<span style="color: #000080;">:</span> A, as<span style="color: #000080;">:</span> List<span style="color: #F78811;">&#91;</span>B<span style="color: #F78811;">&#93;</span><span style="color: #F78811;">&#41;</span> <span style="color: #000080;">=</span>
      as.<span style="color: #000000;">foldLeft</span><span style="color: #F78811;">&#40;</span>a<span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#40;</span>f<span style="color: #F78811;">&#41;</span>
  <span style="color: #F78811;">&#125;</span>
&nbsp;
  <span style="color: #0000ff; font-weight: bold;">val</span> ArrayFoldable <span style="color: #000080;">=</span> <span style="color: #0000ff; font-weight: bold;">new</span> Foldable<span style="color: #F78811;">&#91;</span>Array<span style="color: #F78811;">&#93;</span> <span style="color: #F78811;">&#123;</span>
    <span style="color: #0000ff; font-weight: bold;">def</span> foldl<span style="color: #F78811;">&#91;</span>A, B<span style="color: #F78811;">&#93;</span><span style="color: #F78811;">&#40;</span>f<span style="color: #000080;">:</span> <span style="color: #F78811;">&#40;</span>A, B<span style="color: #F78811;">&#41;</span> <span style="color: #000080;">=&gt;</span> A, a<span style="color: #000080;">:</span> A, as<span style="color: #000080;">:</span> Array<span style="color: #F78811;">&#91;</span>B<span style="color: #F78811;">&#93;</span><span style="color: #F78811;">&#41;</span> <span style="color: #000080;">=</span>
      as.<span style="color: #000000;">foldLeft</span><span style="color: #F78811;">&#40;</span>a<span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#40;</span>f<span style="color: #F78811;">&#41;</span>
  <span style="color: #F78811;">&#125;</span>
<span style="color: #F78811;">&#125;</span>
&nbsp;
<span style="color: #0000ff; font-weight: bold;">sealed</span> <span style="color: #0000ff; font-weight: bold;">trait</span> Ordering
<span style="color: #0000ff; font-weight: bold;">case</span> <span style="color: #0000ff; font-weight: bold;">object</span> LT <span style="color: #0000ff; font-weight: bold;">extends</span> Ordering
<span style="color: #0000ff; font-weight: bold;">case</span> <span style="color: #0000ff; font-weight: bold;">object</span> EQ <span style="color: #0000ff; font-weight: bold;">extends</span> Ordering
<span style="color: #0000ff; font-weight: bold;">case</span> <span style="color: #0000ff; font-weight: bold;">object</span> GT <span style="color: #0000ff; font-weight: bold;">extends</span> Ordering
&nbsp;
<span style="color: #008000; font-style: italic;">// contra</span>
<span style="color: #0000ff; font-weight: bold;">trait</span> Order<span style="color: #F78811;">&#91;</span>A<span style="color: #F78811;">&#93;</span> <span style="color: #F78811;">&#123;</span>
  <span style="color: #0000ff; font-weight: bold;">def</span> compare<span style="color: #F78811;">&#40;</span>a1<span style="color: #000080;">:</span> A, a2<span style="color: #000080;">:</span> A<span style="color: #F78811;">&#41;</span><span style="color: #000080;">:</span> Ordering
&nbsp;
  <span style="color: #0000ff; font-weight: bold;">def</span> min<span style="color: #F78811;">&#40;</span>a1<span style="color: #000080;">:</span> A, a2<span style="color: #000080;">:</span> A<span style="color: #F78811;">&#41;</span> <span style="color: #000080;">=</span>
    <span style="color: #0000ff; font-weight: bold;">if</span><span style="color: #F78811;">&#40;</span>compare<span style="color: #F78811;">&#40;</span>a1, a2<span style="color: #F78811;">&#41;</span> <span style="color: #000080;">==</span> LT<span style="color: #F78811;">&#41;</span> a1 <span style="color: #0000ff; font-weight: bold;">else</span> a2
<span style="color: #F78811;">&#125;</span>
&nbsp;
<span style="color: #0000ff; font-weight: bold;">object</span> Order <span style="color: #F78811;">&#123;</span>
  <span style="color: #0000ff; font-weight: bold;">def</span> order<span style="color: #F78811;">&#91;</span>A<span style="color: #F78811;">&#93;</span><span style="color: #F78811;">&#40;</span>f<span style="color: #000080;">:</span> <span style="color: #F78811;">&#40;</span>A, A<span style="color: #F78811;">&#41;</span> <span style="color: #000080;">=&gt;</span> Ordering<span style="color: #F78811;">&#41;</span><span style="color: #000080;">:</span> Order<span style="color: #F78811;">&#91;</span>A<span style="color: #F78811;">&#93;</span> <span style="color: #000080;">=</span> <span style="color: #0000ff; font-weight: bold;">new</span> Order<span style="color: #F78811;">&#91;</span>A<span style="color: #F78811;">&#93;</span> <span style="color: #F78811;">&#123;</span>
    <span style="color: #0000ff; font-weight: bold;">def</span> compare<span style="color: #F78811;">&#40;</span>a1<span style="color: #000080;">:</span> A, a2<span style="color: #000080;">:</span> A<span style="color: #F78811;">&#41;</span> <span style="color: #000080;">=</span> f<span style="color: #F78811;">&#40;</span>a1, a2<span style="color: #F78811;">&#41;</span>
  <span style="color: #F78811;">&#125;</span>
&nbsp;
  <span style="color: #0000ff; font-weight: bold;">val</span> IntOrder <span style="color: #000080;">=</span> order<span style="color: #F78811;">&#91;</span><span style="color: #9999cc; font-weight: bold;">Int</span><span style="color: #F78811;">&#93;</span><span style="color: #F78811;">&#40;</span><span style="color: #F78811;">&#40;</span>a1, a2<span style="color: #F78811;">&#41;</span> <span style="color: #000080;">=&gt;</span> 
    <span style="color: #0000ff; font-weight: bold;">if</span><span style="color: #F78811;">&#40;</span>a1 <span style="color: #000080;">&gt;</span> a2<span style="color: #F78811;">&#41;</span> GT
    <span style="color: #0000ff; font-weight: bold;">else</span> <span style="color: #0000ff; font-weight: bold;">if</span><span style="color: #F78811;">&#40;</span>a1 <span style="color: #000080;">&lt;</span> a2<span style="color: #F78811;">&#41;</span> LT
    <span style="color: #0000ff; font-weight: bold;">else</span> EQ<span style="color: #F78811;">&#41;</span>
&nbsp;
  <span style="color: #0000ff; font-weight: bold;">val</span> StringOrder <span style="color: #000080;">=</span> order<span style="color: #F78811;">&#91;</span>String<span style="color: #F78811;">&#93;</span><span style="color: #F78811;">&#40;</span><span style="color: #F78811;">&#40;</span>a1, a2<span style="color: #F78811;">&#41;</span> <span style="color: #000080;">=&gt;</span>
    <span style="color: #0000ff; font-weight: bold;">if</span><span style="color: #F78811;">&#40;</span>a1 <span style="color: #000080;">&gt;</span> a2<span style="color: #F78811;">&#41;</span> GT
    <span style="color: #0000ff; font-weight: bold;">else</span> <span style="color: #0000ff; font-weight: bold;">if</span><span style="color: #F78811;">&#40;</span>a1 <span style="color: #000080;">&lt;</span> a2<span style="color: #F78811;">&#41;</span> LT
    <span style="color: #0000ff; font-weight: bold;">else</span> EQ<span style="color: #F78811;">&#41;</span>
<span style="color: #F78811;">&#125;</span>
&nbsp;
<span style="color: #0000ff; font-weight: bold;">object</span> Main <span style="color: #F78811;">&#123;</span>
  <span style="color: #0000ff; font-weight: bold;">import</span> Foldable.<span style="color: #000080;">_</span>
  <span style="color: #0000ff; font-weight: bold;">import</span> Order.<span style="color: #000080;">_</span>
&nbsp;
  <span style="color: #0000ff; font-weight: bold;">def</span> minimum<span style="color: #F78811;">&#91;</span>F<span style="color: #F78811;">&#91;</span><span style="color: #000080;">_</span><span style="color: #F78811;">&#93;</span>, A<span style="color: #F78811;">&#93;</span><span style="color: #F78811;">&#40;</span>as<span style="color: #000080;">:</span> F<span style="color: #F78811;">&#91;</span>A<span style="color: #F78811;">&#93;</span>, order<span style="color: #000080;">:</span> Order<span style="color: #F78811;">&#91;</span>A<span style="color: #F78811;">&#93;</span>, fold<span style="color: #000080;">:</span> Foldable<span style="color: #F78811;">&#91;</span>F<span style="color: #F78811;">&#93;</span><span style="color: #F78811;">&#41;</span> <span style="color: #000080;">=</span>
    <span style="color: #008000; font-style: italic;">// Zm9sZC5yZWR1Y2VsW0FdKChhLCBiKSA9PiBvcmRlci5taW4oYSwgYiksIGFzKQ==</span>
    error<span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;todo&quot;</span><span style="color: #F78811;">&#41;</span>
&nbsp;
  <span style="color: #0000ff; font-weight: bold;">def</span> main<span style="color: #F78811;">&#40;</span>args<span style="color: #000080;">:</span> Array<span style="color: #F78811;">&#91;</span>String<span style="color: #F78811;">&#93;</span><span style="color: #F78811;">&#41;</span> <span style="color: #F78811;">&#123;</span>
    <span style="color: #0000ff; font-weight: bold;">val</span> i <span style="color: #000080;">=</span> minimum<span style="color: #F78811;">&#40;</span>args, StringOrder, ArrayFoldable<span style="color: #F78811;">&#41;</span>
    println<span style="color: #F78811;">&#40;</span>i<span style="color: #F78811;">&#41;</span>
&nbsp;
    <span style="color: #0000ff; font-weight: bold;">val</span> j <span style="color: #000080;">=</span> minimum<span style="color: #F78811;">&#40;</span>List<span style="color: #F78811;">&#40;</span><span style="color: #F78811;">5</span>, <span style="color: #F78811;">8</span>, <span style="color: #F78811;">2</span>, <span style="color: #F78811;">9</span><span style="color: #F78811;">&#41;</span>, IntOrder, ListFoldable<span style="color: #F78811;">&#41;</span>
    println<span style="color: #F78811;">&#40;</span>j<span style="color: #F78811;">&#41;</span>    
  <span style="color: #F78811;">&#125;</span>
<span style="color: #F78811;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.tmorris.net/scala-exercise/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Functional Java 2.21</title>
		<link>http://blog.tmorris.net/functional-java-221/</link>
		<comments>http://blog.tmorris.net/functional-java-221/#comments</comments>
		<pubDate>Fri, 05 Feb 2010 10:49:15 +0000</pubDate>
		<dc:creator>Tony Morris</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.tmorris.net/?p=647</guid>
		<description><![CDATA[Includes a number of bug fixes and an immutable 2-3 finger tree for sequences supporting access to the ends in amortized O(1) time.
]]></description>
			<content:encoded><![CDATA[<p>Includes a number of bug fixes and an immutable 2-3 finger tree for sequences supporting access to the ends in amortized O(1) time.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tmorris.net/functional-java-221/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Higher-order Polymorphism for pseudo-Java</title>
		<link>http://blog.tmorris.net/higher-order-polymorphism-for-pseudo-java/</link>
		<comments>http://blog.tmorris.net/higher-order-polymorphism-for-pseudo-java/#comments</comments>
		<pubDate>Thu, 28 Jan 2010 06:48:14 +0000</pubDate>
		<dc:creator>Tony Morris</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.tmorris.net/?p=642</guid>
		<description><![CDATA[
// Simulate Higher-Order Functions.
// A lambda function is any implementation of this interface.
interface Lambda&#60;X, Y&#62; &#123;
  Y apply&#40;X x&#41;;
&#125;
&#160;
// What is a covariant functor?
// It is any implementation of this interface.
// All implementations must also satisfy:
//   * The law of identity
//   * The law of composition
// (but let's brush that [...]]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="java"><span style="color: #666666; font-style: italic;">// Simulate Higher-Order Functions.</span>
<span style="color: #666666; font-style: italic;">// A lambda function is any implementation of this interface.</span>
<span style="color: #000000; font-weight: bold;">interface</span> Lambda<span style="color: #339933;">&lt;</span>X, Y<span style="color: #339933;">&gt;</span> <span style="color: #009900;">&#123;</span>
  Y apply<span style="color: #009900;">&#40;</span>X x<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// What is a covariant functor?</span>
<span style="color: #666666; font-style: italic;">// It is any implementation of this interface.</span>
<span style="color: #666666; font-style: italic;">// All implementations must also satisfy:</span>
<span style="color: #666666; font-style: italic;">//   * The law of identity</span>
<span style="color: #666666; font-style: italic;">//   * The law of composition</span>
<span style="color: #666666; font-style: italic;">// (but let's brush that to the side)</span>
<span style="color: #000000; font-weight: bold;">interface</span> Functor<span style="color: #339933;">&lt;</span>F<span style="color: #339933;">&gt;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #339933;">&lt;</span>A, B<span style="color: #339933;">&gt;</span> F<span style="color: #339933;">&lt;</span>B<span style="color: #339933;">&gt;</span> fmap<span style="color: #009900;">&#40;</span>F<span style="color: #339933;">&lt;</span>A<span style="color: #339933;">&gt;</span> a, Lambda<span style="color: #339933;">&lt;</span>A, B<span style="color: #339933;">&gt;</span> f<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.LinkedList</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Here is the functor for Java's LinkedList.</span>
<span style="color: #666666; font-style: italic;">// It maps a function across each element of the list and returns a new one.</span>
<span style="color: #666666; font-style: italic;">// (trust me, it satisfies the two laws).</span>
<span style="color: #000000; font-weight: bold;">class</span> LinkedListFunctor <span style="color: #000000; font-weight: bold;">implements</span> Functor<span style="color: #339933;">&lt;</span>LinkedList<span style="color: #339933;">&gt;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #339933;">&lt;</span>A, B<span style="color: #339933;">&gt;</span> LinkedList<span style="color: #339933;">&lt;</span>B<span style="color: #339933;">&gt;</span> fmap<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> LinkedList<span style="color: #339933;">&lt;</span>A<span style="color: #339933;">&gt;</span> a, <span style="color: #000000; font-weight: bold;">final</span> Lambda<span style="color: #339933;">&lt;</span>A, B<span style="color: #339933;">&gt;</span> f<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">final</span> LinkedList<span style="color: #339933;">&lt;</span>B<span style="color: #339933;">&gt;</span> r <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> LinkedList<span style="color: #339933;">&lt;</span>B<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> A x <span style="color: #339933;">:</span> a<span style="color: #009900;">&#41;</span>
      r.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span>f.<span style="color: #006633;">apply</span><span style="color: #009900;">&#40;</span>x<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">return</span> r<span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Here is a trivial Java data type.</span>
<span style="color: #666666; font-style: italic;">// It happens to be a covariant functor.</span>
<span style="color: #666666; font-style: italic;">// Let's witness its instance...</span>
<span style="color: #000000; font-weight: bold;">interface</span> IntConverter<span style="color: #339933;">&lt;</span>A<span style="color: #339933;">&gt;</span> <span style="color: #009900;">&#123;</span>
  A convert<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// The Functor instance for the IntConverter.</span>
<span style="color: #000000; font-weight: bold;">class</span> IntConverterFunctor <span style="color: #000000; font-weight: bold;">implements</span> Functor<span style="color: #339933;">&lt;</span>IntConverter<span style="color: #339933;">&gt;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #339933;">&lt;</span>A, B<span style="color: #339933;">&gt;</span> IntConverter<span style="color: #339933;">&lt;</span>B<span style="color: #339933;">&gt;</span> fmap<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> IntConverter<span style="color: #339933;">&lt;</span>A<span style="color: #339933;">&gt;</span> a, <span style="color: #000000; font-weight: bold;">final</span> Lambda<span style="color: #339933;">&lt;</span>A, B<span style="color: #339933;">&gt;</span> f<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> IntConverter<span style="color: #339933;">&lt;</span>B<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">public</span> B convert<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> f.<span style="color: #006633;">apply</span><span style="color: #009900;">&#40;</span>a.<span style="color: #006633;">convert</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// So why do we care?</span>
<span style="color: #666666; font-style: italic;">// Because it prevents an enormous (*enormous*, *ENORMOUS!*)</span>
<span style="color: #666666; font-style: italic;">// amount of otherwise needless repetition.</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> FunctorX <span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// Gives rise to:</span>
  <span style="color: #666666; font-style: italic;">// LinkedList&lt;Lambda&lt;A, B&gt;&gt; =&gt; A =&gt; LinkedList&lt;B&gt;</span>
  <span style="color: #666666; font-style: italic;">// IntConverter&lt;Lambda&lt;A, B&gt;&gt; =&gt; A =&gt; IntConverter&lt;B&gt;</span>
  <span style="color: #666666; font-style: italic;">// ...</span>
  <span style="color: #666666; font-style: italic;">// F&lt;Lambda&lt;A, B&gt;&gt; =&gt; A =&gt; F&lt;B&gt; (for many values of F)</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #339933;">&lt;</span>A, B, F<span style="color: #339933;">&gt;</span> F<span style="color: #339933;">&lt;</span>B<span style="color: #339933;">&gt;</span> fapply<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> Functor<span style="color: #339933;">&lt;</span>F<span style="color: #339933;">&gt;</span> f, <span style="color: #000000; font-weight: bold;">final</span> F<span style="color: #339933;">&lt;</span>Lambda<span style="color: #339933;">&lt;</span>A, B<span style="color: #339933;">&gt;&gt;</span> lam, <span style="color: #000000; font-weight: bold;">final</span> A a<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">return</span> f.<span style="color: #006633;">fmap</span><span style="color: #009900;">&#40;</span>lam, <span style="color: #000000; font-weight: bold;">new</span> Lambda<span style="color: #339933;">&lt;</span>Lambda<span style="color: #339933;">&lt;</span>A, B<span style="color: #339933;">&gt;</span>, B<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">public</span> B apply<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> Lambda<span style="color: #339933;">&lt;</span>A, B<span style="color: #339933;">&gt;</span> z<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> z.<span style="color: #006633;">apply</span><span style="color: #009900;">&#40;</span>a<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// ... etcetra.</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// It turns a linear amount of code into a constant amount of code.</span>
<span style="color: #666666; font-style: italic;">// Similarly a sort function that runs on lists of</span>
<span style="color: #666666; font-style: italic;">// any type (provided a comparator) alleviates the need for linear</span>
<span style="color: #666666; font-style: italic;">// amounts of code (a sort function for each possible list element type).</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.tmorris.net/higher-order-polymorphism-for-pseudo-java/feed/</wfw:commentRss>
		</item>
		<item>
		<title>MSN/Yahoo! web spiders blocked</title>
		<link>http://blog.tmorris.net/msnyahoo-web-spiders-blocked/</link>
		<comments>http://blog.tmorris.net/msnyahoo-web-spiders-blocked/#comments</comments>
		<pubDate>Sun, 24 Jan 2010 13:03:20 +0000</pubDate>
		<dc:creator>Tony Morris</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://blog.tmorris.net/?p=640</guid>
		<description><![CDATA[I have blocked the msnbot and yahoo! web spiders from indexing this site (and all others at this IP address). They choke up the network with distributed multiple connections. Pretty silly/primitive technique of indexing a web site.
]]></description>
			<content:encoded><![CDATA[<p>I have blocked the msnbot and yahoo! web spiders from indexing this site (and all others at this IP address). They choke up the network with distributed multiple connections. Pretty silly/primitive technique of indexing a web site.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tmorris.net/msnyahoo-web-spiders-blocked/feed/</wfw:commentRss>
		</item>
		<item>
		<title>What is Haskell&#8217;s primary feature?</title>
		<link>http://blog.tmorris.net/what-is-haskells-primary-feature/</link>
		<comments>http://blog.tmorris.net/what-is-haskells-primary-feature/#comments</comments>
		<pubDate>Fri, 22 Jan 2010 09:30:37 +0000</pubDate>
		<dc:creator>Tony Morris</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.tmorris.net/?p=636</guid>
		<description><![CDATA[Today I was asked what Haskell&#8217;s main feature is. The answer is its non-strict evaluation.
Java is a strictly evaluated language. Consider this Java program:

class C &#123;
  static String i&#40;&#41; &#123;
    throw new Error&#40;&#34;boo!&#34;&#41;;
  &#125;
&#160;
  static &#60;A&#62; int f&#40;A a&#41; &#123;
    return 3;
  &#125;
&#160;
  public [...]]]></description>
			<content:encoded><![CDATA[<p>Today I was asked what Haskell&#8217;s main feature is. The answer is its non-strict evaluation.</p>
<p>Java is a strictly evaluated language. Consider this Java program:</p>

<div class="wp_syntax"><div class="code"><pre class="java"><span style="color: #000000; font-weight: bold;">class</span> C <span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">String</span> i<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Error</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;boo!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #339933;">&lt;</span>A<span style="color: #339933;">&gt;</span> <span style="color: #000066; font-weight: bold;">int</span> f<span style="color: #009900;">&#40;</span>A a<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">int</span> k <span style="color: #339933;">=</span> f<span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>k<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The program fails with a runtime error.</p>
<p>Consider this (otherwise equivalent) Haskell program:</p>

<div class="wp_syntax"><div class="code"><pre class="haskell">i <span style="color: #339933; font-weight: bold;">=</span> <span style="font-weight: bold;">error</span> <span style="background-color: #3cb371;">&quot;boo!&quot;</span>
&nbsp;
f a <span style="color: #339933; font-weight: bold;">=</span> <span style="color: red;">3</span>
&nbsp;
main <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">let</span> k <span style="color: #339933; font-weight: bold;">=</span> f i
       <span style="color: #06c; font-weight: bold;">in</span> <span style="font-weight: bold;">print</span> k</pre></div></div>

<p>The program prints 3 and does not fail like the Java program. This is a key property of Haskell with very far reaching implications. One of those implications is that Haskell is a pure language. There are many more implications, particularly with respect to the compositional properties of programs. </p>
<p>Haskell&#8217;s evaluation model and its implications is perhaps its most widely misunderstood feature. While the benefits are (enormously) enormous, they are far too deep to consider writing a short article about.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tmorris.net/what-is-haskells-primary-feature/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
