<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
    xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:at="http://www.sixapart.com/ns/at"
    xmlns:icbm="http://postneo.com/icbm"
    xmlns:rvw="http://purl.org/NET/RVW/0.2/"
    xmlns:media="http://search.yahoo.com/mrss">
    <channel>
        <title>osfameron’s blog</title>
        <link>http://osfameron.vox.com/library/posts/page/1/</link>
        <description></description>
        <language>en</language>
        <generator>Vox</generator>
        <lastBuildDate>Mon, 30 Jun 2008 23:51:30 +0100</lastBuildDate>
        <copyright>Copyright 2008</copyright>
        <docs>http://blogs.law.harvard.edu/tech/rss</docs>  
 
        <item>
            <title>Blog move</title>
            <link>http://osfameron.vox.com/library/post/blog-move.html?_c=feed-rss-full</link>   
            <author>nobody@vox.com(osfameron)</author>
            <comments>http://osfameron.vox.com/library/post/blog-move.html?_c=feed-rss-full</comments>
            <guid isPermaLink="true">http://osfameron.vox.com/library/post/blog-move.html?_c=feed-rss-full</guid> 
            <pubDate>Mon, 30 Jun 2008 23:51:30 +0100</pubDate>         
            
            <description>    &lt;p&gt;I&amp;#39;ve enjoyed using Vox.com over the last couple of months but I&amp;#39;m finally taking the plunge and moving the blog to &lt;a href=&quot;http://greenokapi.net/blog/&quot;&gt;greenokapi.net/blog&lt;/a&gt;.&amp;#160; &lt;/p&gt;&lt;p&gt;Though I&amp;#39;ve occasionally wanted more flexibility, the trade-off with a hosted service is that you waste no time tinkering, the only thing you can do is write.&amp;#160; But the fact that Vox doesn&amp;#39;t, at time of writing, handle comments gracefully reduces the value of the blog -- I&amp;#39;ve had some great comments and suggestions from readers, and I&amp;#39;d say that the feedback is one of the most useful effects of having a blog at all.&amp;#160; Vox&amp;#39;s insistence on signing up in order to comment is just a barrier to feedback, but I got tired of comments like &amp;quot;Hey, where did my last comment go?&amp;quot; because the default formatter apparently doesn&amp;#39;t like code.&lt;/p&gt;&lt;p&gt;Of course, Wordpress has its hatefulness too.&amp;#160; For a code-oriented blog you &lt;em&gt;need&lt;/em&gt; the Text Control plugin, which is the only way to prevent it from moronizing newlines and making quotes &amp;quot;smart&amp;quot;.&amp;#160; (By default, Wordpress even turns ascii smileys into horrid yellow gifs, though this at least can be switched off easily).&lt;br /&gt; &lt;/p&gt;    &lt;p style=&quot;clear:both;&quot;&gt; 
    &lt;a href=&quot;http://osfameron.vox.com/library/post/blog-move.html?_c=feed-rss-full#comments&quot;&gt;Read and post comments&lt;/a&gt;   |   
    &lt;a href=&quot;http://www.vox.com/share/6a00c225240a9af21900fad696537b0004?_c=feed-rss-full&quot;&gt;Send to a friend&lt;/a&gt; 
&lt;/p&gt;
 
            </description>   
        </item> 
 
        <item>
            <title>Five things I hate about Perl</title>
            <link>http://osfameron.vox.com/library/post/five-things-i-hate-about-perl.html?_c=feed-rss-full</link>   
            <author>nobody@vox.com(osfameron)</author>
            <comments>http://osfameron.vox.com/library/post/five-things-i-hate-about-perl.html?_c=feed-rss-full</comments>
            <guid isPermaLink="true">http://osfameron.vox.com/library/post/five-things-i-hate-about-perl.html?_c=feed-rss-full</guid> 
            <pubDate>Mon, 23 Jun 2008 08:04:42 +0100</pubDate>         
            
            <description>    &lt;p&gt;
Enough
&lt;a&gt;advocacy&lt;/a&gt;, let&amp;#39;s get to the nitty gritty of 5 things I hate about Perl.
(&lt;a href=&quot;http://use.perl.org/%7Ebrian_d_foy/journal/32556&quot;&gt;After brian d foy&lt;/a&gt;.)
&lt;/p&gt;


&lt;ol&gt;&lt;li&gt;
&lt;p&gt;
The difference between &lt;strong&gt;list and scalar context&lt;/strong&gt; is subtle.  One bug that bites people too
often is this (for some value of &amp;quot;people&amp;quot;, including me, far too often):

&lt;/p&gt;&lt;blockquote&gt;
&lt;pre&gt;sub myfunc { return }&lt;br /&gt;    my $scalar = myfunc(); # contains undef&lt;br /&gt;&lt;br /&gt;    my %hash = (&lt;br /&gt;        key =&amp;gt; &amp;#39;value&amp;#39;,&lt;br /&gt;        key =&amp;gt; myfunc(),&lt;br /&gt;    );&lt;/pre&gt;
&lt;/blockquote&gt;

In scalar context, we get &lt;tt&gt;undef&lt;/tt&gt;.  But in list context, myfunc returns
a list of zero elements.  Guess which context hash declarations are in...


&lt;p&gt;
Luckily in this case we&amp;#39;ll get a &amp;quot;Odd number of elements in hash declaration&amp;quot; warning.
Perl&amp;#39;s warnings are mostly very useful and surprisingly helpful.  However:
&lt;/p&gt;

&lt;/li&gt;&lt;li&gt;
&lt;p&gt;
Some &lt;strong&gt;warnings&lt;/strong&gt; suck.  Yes, some of them almost always point out an error (the void context
error is useful: I usually find it means I&amp;#39;ve written:  &lt;tt&gt;my $x =&amp;gt; 1&lt;/tt&gt; instead of
&lt;tt&gt;my $x = 1&lt;/tt&gt;) but some are more irritating.
&lt;/p&gt;

&lt;p&gt;
When was the last time an &amp;#39;uninitialized&amp;#39; warning had any effect on your code apart from making
you have to sprinkle &lt;tt&gt;$x ||= &amp;#39;&amp;#39;&lt;/tt&gt; throughout your code?  Yet I usually restrain
myself from adding &lt;tt&gt;no warnings &amp;#39;uninitialized&amp;#39;&lt;/tt&gt; because maybe one time in a hundred
there&amp;#39;s a genuine bug I need to know about.
&lt;/p&gt;

&lt;p&gt;
Similarly &amp;#39;once&amp;#39; warnings sound useful, but in practise are usually because you&amp;#39;ve
referred to a magic global that&amp;#39;s used &lt;em&gt;plenty&lt;/em&gt; of times in the library you want to use.
For example, from &lt;tt&gt;List::Util&lt;/tt&gt;&amp;#39;s documentation,

&lt;/p&gt;&lt;blockquote&gt;
&lt;pre&gt;my $sum = reduce { $a + $b } @list;&lt;/pre&gt;
&lt;/blockquote&gt;

will warn about $main::a and $main::b being used only once.  $a and $b are the canonical
magical variables, wtf is that about?  (mst suggests that these warnings are inhibited
for &lt;tt&gt;sort&lt;/tt&gt; only, which was their first use case).


&lt;/li&gt;&lt;li&gt;
&lt;p&gt;
&lt;strong&gt;Argument passing&lt;/strong&gt;.  Yes, it&amp;#39;s really flexible to be able to unpack
&lt;strong&gt;@_&lt;/strong&gt; in any way you want but I&amp;#39;d like a proper way of doing it.  (And yes,
there are all kinds of solutions including Devel::Declare, but none are
standard yet).  Oh, and we don&amp;#39;t have full destructuring bind, so yes, you can
do &lt;tt&gt;($x,$y) = ($y,$x)&lt;/tt&gt; and &lt;tt&gt;my ($self, %args)=@_&lt;/tt&gt;, but not &lt;tt&gt;my
({foo=&amp;gt;$foo}, [undef,undef,$bar]) = @_&lt;/tt&gt;.
&lt;/p&gt;

&lt;/li&gt;&lt;li&gt;
&lt;p&gt;
It&amp;#39;s a &lt;strong&gt;big&lt;/strong&gt; language, with lots of syntax, several powerful minilanguages, a vast array of
standard idioms, a large set of standard libs (including various incompatible ways of doing
similar tasks) and a truly staggering number of 3rd party libs, CPAN, with even more ways of
doing it.  Actually, learning a big language is fine, but the bigness is one of the things
making Perl difficult to parse.  The other is the sheer amount of flexibility that Perl
gives you to shoot yourself in the foot, change the way the language is parsed etc.  Only
Perl can parse Perl, and usually only after executing part of your code first.  Yay for exploits
on your language-aware text editor!
&lt;/p&gt;

&lt;/li&gt;&lt;li&gt;
&lt;p&gt;
&lt;strong&gt;Functional programming&lt;/strong&gt; isn&amp;#39;t easy or elegant.  Yes, we have first class
functions, but things like argument unpacking being ugly make it less
convenient.  Little kludges like the functions passed to map and grep taking
&lt;tt&gt;$_&lt;/tt&gt; rather than the usual argument list &lt;tt&gt;@_&lt;/tt&gt; just add to the fun
(&lt;tt&gt;$_&lt;/tt&gt; seems like a special-cased points-free hack, and it&amp;#39;s far less
consistent or common than Haskell&amp;#39;s currying)
&lt;/p&gt;

&lt;p&gt;
I also dislike that regex substitution etc. can&amp;#39;t be done as a non-destructive function.
&lt;/p&gt;
&lt;/li&gt;&lt;/ol&gt;

&lt;p&gt;
Hmmm, there are probably more things, but those are the main ones.  In particular 
I don&amp;#39;t hate references (yes, they take a little learning, and I&amp;#39;m aware that&amp;#39;s a
stumbling block for most learners, but they are quite sensible once you do)
or OO (baroque, but quite capable, and see &lt;a href=&quot;http://www.iinteractive.com/moose/&quot;&gt;Moose&lt;/a&gt; for a cute modern take on
it).
&lt;/p&gt;     &lt;p style=&quot;clear:both;&quot;&gt; 
    &lt;a href=&quot;http://osfameron.vox.com/library/post/five-things-i-hate-about-perl.html?_c=feed-rss-full#comments&quot;&gt;Read and post comments&lt;/a&gt;   |   
    &lt;a href=&quot;http://www.vox.com/share/6a00c225240a9af21900fa96818a9b0003?_c=feed-rss-full&quot;&gt;Send to a friend&lt;/a&gt; 
&lt;/p&gt;
 
            </description> 
            <category domain="http://osfameron.vox.com/tags/">perl</category> 
            <category domain="http://osfameron.vox.com/tags/">meme</category> 
            <category domain="http://osfameron.vox.com/tags/">hate</category>   
        </item> 
 
        <item>
            <title>More Countdown: laziness, Scheme, and German frogs</title>
            <link>http://osfameron.vox.com/library/post/more-countdown-laziness-scheme-and-german-frogs.html?_c=feed-rss-full</link>   
            <author>nobody@vox.com(osfameron)</author>
            <comments>http://osfameron.vox.com/library/post/more-countdown-laziness-scheme-and-german-frogs.html?_c=feed-rss-full</comments>
            <guid isPermaLink="true">http://osfameron.vox.com/library/post/more-countdown-laziness-scheme-and-german-frogs.html?_c=feed-rss-full</guid> 
            <pubDate>Fri, 20 Jun 2008 08:32:16 +0100</pubDate>         
            
            <description>    &lt;p&gt;
The Countdown code I showed you isn&amp;#39;t really taking advantage of Haskell&amp;#39;s laziness.
We should only have to check entries up until the point that we have enough matches
(in the current code &amp;#39;&lt;tt&gt;take 4 $ getAnagrams&lt;/tt&gt;&amp;#39;) and that&amp;#39;s good.  However, we
have to generate the whole powerset first, so that we can sort it in reverse order
of length.  Ideally, we&amp;#39;d generate the powerset breadth-first, in order of length.
&lt;/p&gt;

&lt;p&gt;
OK, so generating the powerset doesn&amp;#39;t take all that much time and this isn&amp;#39;t a good
&lt;em&gt;optimization&lt;/em&gt; as such, but I did think it might be fun trying to do the breadth
first powerset, as all the examples I&amp;#39;d seen had been depth first.
&lt;/p&gt;

&lt;p&gt;
But first: an interlude to marvel at one of the scariest things I&amp;#39;ve seen this year.
A &lt;a href=&quot;http://community.livejournal.com/evan_tech/220036.html&quot;&gt;monadic definition of
powerset&lt;/a&gt;.

&lt;/p&gt;&lt;blockquote&gt;
&lt;pre&gt;import Control.Monad (filterM)&lt;br /&gt;powerset = filterM (const [True, False])&lt;br /&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;p&gt;

I&amp;#39;m not even going to attempt to twist my head around that now, but it&amp;#39;s very beautiful,
though it&amp;#39;s impossible to tell just by reading it what the intent of the code is.


&lt;p&gt;
I asked on #london.pm if anyone knew good breadth-first algorithms for powerset.  Joel
helpfully pasted the following

&lt;/p&gt;&lt;blockquote&gt;
&lt;pre&gt;(define (combinations set n)&lt;br /&gt;  (if (zero? n)&lt;br /&gt;    (list &amp;#39;())&lt;br /&gt;    (let ((n2 (- n 1)))&lt;br /&gt;      (pair-fold-right&lt;br /&gt;       (lambda (pr acc)&lt;br /&gt;         (let ((first (car pr)))&lt;br /&gt;           (append (map (cut cons first &amp;lt;&amp;gt;)&lt;br /&gt;                        (combinations (cdr pr) n2))&lt;br /&gt;                   acc)))&lt;br /&gt;       &amp;#39;()&lt;br /&gt;       set))))&lt;br /&gt; &lt;br /&gt;(define (power-set set)&lt;br /&gt;  (let ((size (length set)))&lt;br /&gt;    (let loop ((i 0))&lt;br /&gt;      (if (&amp;gt; i size)&lt;br /&gt;        &amp;#39;()&lt;br /&gt;        (append (combinations set i)&lt;br /&gt;                (loop (+ i 1)))))))&lt;/pre&gt;&lt;/blockquote&gt;

I think it surprised Joel (and actually, it surprised me a little) that I was more or less
unable to read this at all.  Yes, I know that the syntax of Lisp is incredibly simple, and
you can learn all the syntax of Scheme in 20 minutes or whatever.  The noise of the
parenthesis, the &lt;tt&gt;cdr&lt;/tt&gt;s etc. is just noise, you can filter it out if you look at
it calmly. But I still don&amp;#39;t understand where the pairs are in &lt;tt&gt;pair-fold-right&lt;/tt&gt;,
and &lt;tt&gt;cut&lt;/tt&gt; apparently does something similar to currying, but what does that &lt;em&gt;mean&lt;/em&gt;
in context?&lt;/p&gt;

&lt;p&gt;
To cut a long story short, I was reading this as a foreign language rather than a piece of
generic pseudocode.  When I was very little, I read with my mother a picture book about
frogs, in German.  With the help of the pictures and a little imagination, it was easy to
tell which word meant &amp;quot;frog&amp;quot;, which meant &amp;quot;tree&amp;quot;, and what the sense of the story was.
After we finished, very puffed up with just how damn clever I was, I started trying to
read it again, and got utterly confused about all these strange words like &amp;#39;&lt;tt&gt;in&lt;/tt&gt;&amp;#39; 
and &amp;#39;&lt;tt&gt;auf&lt;/tt&gt;&amp;#39; and &amp;#39;&lt;tt&gt;dem&lt;/tt&gt;&amp;#39; that I just hadn&amp;#39;t worried about the first time
around.
&lt;/p&gt;
&lt;p&gt;
So... trying to see the frog for the trees, we can see that
&lt;tt&gt;combinations&lt;/tt&gt; gives every set of combinations of a particular length,
and that &lt;tt&gt;power-set&lt;/tt&gt; merely loops through &lt;tt&gt;0..length&lt;/tt&gt;, appending the
combinations found for that length.
&lt;/p&gt;

&lt;p&gt;
We can write combinations as a variant on the original powerset function, but which refuses
to carry on once it&amp;#39;s got enough letters:

&lt;/p&gt;&lt;blockquote&gt;
&lt;pre&gt;combinations xs n = comb&amp;#39; xs n (length xs)&lt;br /&gt;&lt;br /&gt;comb&amp;#39; xss@(x:xs) n l | n == 0 = [[]]&lt;br /&gt;                     | l == n = [xss]&lt;br /&gt;                     | otherwise = (map (x:) $ comb&amp;#39; xs (n-1) (l-1)) ++ (comb&amp;#39; xs n (l-1))&lt;br /&gt;comb&amp;#39; [] _ _ = [[]]&lt;/pre&gt;
&lt;/blockquote&gt;&lt;p&gt;

And powerset is easy as:

&lt;blockquote&gt;
&lt;pre&gt;powerset xs = powerset&amp;#39; xs (length xs)&lt;br /&gt;powerset&amp;#39; xs l = if l &amp;lt; minLength&lt;br /&gt;                    then []&lt;br /&gt;                    else (combinations xs l) ++ (powerset&amp;#39; xs (l-1))&lt;/pre&gt;&lt;p&gt;

minLength = 3
&lt;/p&gt;&lt;/blockquote&gt;

We can now remove out the lines with &lt;tt&gt;sortBy&lt;/tt&gt; and &lt;tt&gt;filter longEnough&lt;/tt&gt;,
as the new definition already presents the items in the right order.


&lt;p&gt;
Does this make it any faster?  Apparently not:  as I guessed, powerset is not the
hotspot.  I guess that the problem is the repeated lookups in the Data.Map — any
suggestions on how to profile the Haskell code, and better algorithms to deal with it?
&lt;/p&gt; &lt;/p&gt;    &lt;p style=&quot;clear:both;&quot;&gt; 
    &lt;a href=&quot;http://osfameron.vox.com/library/post/more-countdown-laziness-scheme-and-german-frogs.html?_c=feed-rss-full#comments&quot;&gt;Read and post comments&lt;/a&gt;   |   
    &lt;a href=&quot;http://www.vox.com/share/6a00c225240a9af21900fa9680035a0002?_c=feed-rss-full&quot;&gt;Send to a friend&lt;/a&gt; 
&lt;/p&gt;
 
            </description> 
            <category domain="http://osfameron.vox.com/tags/">countdown</category> 
            <category domain="http://osfameron.vox.com/tags/">haskell</category> 
            <category domain="http://osfameron.vox.com/tags/">scheme</category>   
        </item> 
 
        <item>
            <title>Schwartzian transform in Haskell</title>
            <link>http://osfameron.vox.com/library/post/schwartzian-transform-in-haskell.html?_c=feed-rss-full</link>   
            <author>nobody@vox.com(osfameron)</author>
            <comments>http://osfameron.vox.com/library/post/schwartzian-transform-in-haskell.html?_c=feed-rss-full</comments>
            <guid isPermaLink="true">http://osfameron.vox.com/library/post/schwartzian-transform-in-haskell.html?_c=feed-rss-full</guid> 
            <pubDate>Wed, 18 Jun 2008 22:53:28 +0100</pubDate>         
            
            <description>    &lt;p&gt;
In the last post, I mentioned that we might be able to improve the performance
of our sort using a 
&amp;quot;&lt;a&gt;http://en.wikipedia.org/wiki/Schwartzian_transform&lt;/a&gt;&amp;quot;.

&lt;/p&gt;&lt;p&gt;
This basically involves precaching the expensive calculation (in this case, &lt;tt&gt;length&lt;/tt&gt;),
sorting by the cached value, then taking just the original values.

&lt;/p&gt;&lt;p&gt;
Let&amp;#39;s test with a list of words:

&lt;/p&gt;&lt;blockquote&gt;
&lt;pre&gt;words &amp;quot;If on a winter&amp;#39;s night a traveller&amp;quot;&lt;/pre&gt;
&lt;/blockquote&gt;


&lt;p&gt;
So instead of the original &lt;tt&gt;sortBy (flip $ comparing length)&lt;/tt&gt;, we&amp;#39;d have
something like:

&lt;/p&gt;&lt;blockquote&gt;
&lt;pre&gt;  map fst &lt;br /&gt; . sortBy (flip $ comparing snd)  &lt;br /&gt; . map (id &amp;amp;&amp;amp;&amp;amp; length)&lt;br /&gt;&lt;/pre&gt;
&lt;/blockquote&gt;

&lt;p&gt;
Let&amp;#39;s read it from the bottom.  First of all we create a list of tuples using the rather
wonderful &lt;tt&gt;&amp;amp;&amp;amp;&amp;amp;&lt;/tt&gt; operator from Control.Arrow.

&lt;/p&gt;&lt;blockquote&gt;
&lt;pre&gt;[(&amp;quot;If&amp;quot;,2),(&amp;quot;on&amp;quot;,2),(&amp;quot;a&amp;quot;,1),(&amp;quot;winter&amp;#39;s&amp;quot;,8),(&amp;quot;night&amp;quot;,5),(&amp;quot;a&amp;quot;,1),(&amp;quot;traveller&amp;quot;,9)]&lt;/pre&gt;
&lt;/blockquote&gt;

&lt;p&gt;
Then we sort comparing the &lt;em&gt;new&lt;/em&gt; second field of this tuple.

&lt;/p&gt;&lt;blockquote&gt;
&lt;pre&gt;[(&amp;quot;traveller&amp;quot;,9),(&amp;quot;winter&amp;#39;s&amp;quot;,8),(&amp;quot;night&amp;quot;,5),(&amp;quot;If&amp;quot;,2),(&amp;quot;on&amp;quot;,2),(&amp;quot;a&amp;quot;,1),(&amp;quot;a&amp;quot;,1)]&lt;br /&gt;&lt;/pre&gt;&lt;/blockquote&gt;

&lt;p&gt;
Finally we map again, getting just the first element of the tuple.
&lt;/p&gt;&lt;blockquote&gt;
&lt;pre&gt;[&amp;quot;traveller&amp;quot;,&amp;quot;winter&amp;#39;s&amp;quot;,&amp;quot;night&amp;quot;,&amp;quot;If&amp;quot;,&amp;quot;on&amp;quot;,&amp;quot;a&amp;quot;,&amp;quot;a&amp;quot;]&lt;br /&gt;&lt;/pre&gt;&lt;/blockquote&gt;

&lt;p&gt;
And we can easily abstract this with a new function

&lt;/p&gt;&lt;blockquote&gt;
&lt;pre&gt;sortST cmp f = map fst&lt;br /&gt;             . sortBy (cmp snd)&lt;br /&gt;             . map (id &amp;amp;&amp;amp;&amp;amp; f)&lt;/pre&gt;
&lt;/blockquote&gt;

&lt;p&gt;
Now we can write:

&lt;/p&gt;&lt;blockquote&gt;
&lt;pre&gt;sortST       comparing  length listOfWords&lt;br /&gt;sortST (flip.comparing) length listOfWords&lt;br /&gt;&lt;/pre&gt;
&lt;/blockquote&gt;

&lt;p&gt;
This is very similar to the sortBy syntax, except that we&amp;#39;ve separated out the &amp;quot;comparing&amp;quot;
from the &amp;quot;length&amp;quot; clause, in order to compose the two separately for the new transformation.
&lt;/p&gt;     &lt;p style=&quot;clear:both;&quot;&gt; 
    &lt;a href=&quot;http://osfameron.vox.com/library/post/schwartzian-transform-in-haskell.html?_c=feed-rss-full#comments&quot;&gt;Read and post comments&lt;/a&gt;   |   
    &lt;a href=&quot;http://www.vox.com/share/6a00c225240a9af21900fa967f97ec0002?_c=feed-rss-full&quot;&gt;Send to a friend&lt;/a&gt; 
&lt;/p&gt;
 
            </description> 
            <category domain="http://osfameron.vox.com/tags/">perl</category> 
            <category domain="http://osfameron.vox.com/tags/">haskell</category>   
        </item> 
 
        <item>
            <title>Countdown words game solver in Haskell</title>
            <link>http://osfameron.vox.com/library/post/countdown-words-game-solver-in-haskell.html?_c=feed-rss-full</link>   
            <author>nobody@vox.com(osfameron)</author>
            <comments>http://osfameron.vox.com/library/post/countdown-words-game-solver-in-haskell.html?_c=feed-rss-full</comments>
            <guid isPermaLink="true">http://osfameron.vox.com/library/post/countdown-words-game-solver-in-haskell.html?_c=feed-rss-full</guid> 
            <pubDate>Wed, 18 Jun 2008 13:02:12 +0100</pubDate>         
            
            <description>    &lt;p&gt;
Will on #geekup has been working on a 
&lt;a href=&quot;http://www.channel4.com/entertainment/tv/microsites/C/countdown/index.html&quot;&gt;Countdown&lt;/a&gt;
&lt;a href=&quot;http://countdown.willboyce.com/&quot;&gt;letters and numbers game
solver&lt;/a&gt; written in Python.  I thought it&amp;#39;d be fun to try to do it in Haskell,
and started with the letters game (anagram) solver.
&lt;/p&gt;
&lt;p&gt;
Starting with a string of jumbled letters, the goal is to make the longest possible
anagram.  I remember the first time I tried to solve anagrams I jumped into the
problem without thinking and got mixed up in all kinds of complicated combinatorial
mess.  The actual answer is very simple:  let&amp;#39;s take two words which are anagrams of
each other:

    &lt;/p&gt;&lt;ul&gt;&lt;li&gt;monad&lt;/li&gt;&lt;li&gt;nomad&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;

Both of them contain the same letters, so they are identical in some form of &amp;quot;canonical
representation&amp;quot;, for example

    &lt;ul&gt;&lt;li&gt;&lt;tt&gt;{a:1, d:1, m:1, n:1, o:1}&lt;/tt&gt; -- dictionary mapping letter to number of times used&lt;/li&gt;&lt;li&gt;&lt;tt&gt;&amp;quot;admno&amp;quot;&lt;/tt&gt; -- a string with the letters sorted
    &lt;/li&gt;&lt;/ul&gt;

So we just need to consider all the subsets of the original jumbled letters in turn, and 
compare them against a map of:: &lt;tt&gt;canonical representation -&amp;gt; [list of words]&lt;/tt&gt;.

&lt;p&gt;
So for example:
&lt;/p&gt;&lt;blockquote&gt;&lt;pre&gt;pmqnrdzoa&lt;br /&gt;...&lt;br /&gt;&amp;#160;m&amp;#160;n&amp;#160;d&amp;#160;oa&lt;br /&gt;...&lt;/pre&gt;&lt;/blockquote&gt;

This function is called a &lt;em&gt;powerset&lt;/em&gt;.  I&amp;#39;m lazy so I googled 
&lt;a href=&quot;http://www.haskell.org/pipermail/haskell-cafe/2003-June/004484.html&quot;&gt;a definition&lt;/a&gt;.
We want the longest words first.  The definition of powerset I found does a
&lt;em&gt;depth first search&lt;/em&gt; so it&amp;#39;s not in order of length.  What we want to do
is to work on a list like this

&lt;blockquote&gt;&lt;pre&gt;list s =&lt;br /&gt;                  sortBy (flip $ comparing length)  -- longest first&lt;br /&gt;                . nub                -- unique entries only&lt;br /&gt;                . powerset           -- all combinations of &lt;br /&gt;                . canonicalize       -- canonical (sorted) string&lt;br /&gt;                $ s&lt;/pre&gt;&lt;/blockquote&gt;

where &lt;em&gt;canonicalize&lt;/em&gt; is just &lt;tt&gt;sort . map toLower . filter isLetter&lt;/tt&gt;.

&lt;p&gt;
&lt;em&gt;comparing&lt;/em&gt; is a nice litle utility sub that makes the above effectively the
same as (\a b -&amp;gt; length a `compare` length b).  We then &lt;em&gt;flip&lt;/em&gt; it to reverse the
ordering (and this is actually a good use for flip ;-).
&lt;/p&gt;
&lt;p&gt;
Ordering by length is potentially inefficient — it checks the length of each
element twice, and unlike Perl (where a string knows its own length), a string is
just a list, so it has to descend the list to find it out.  This is easy to optimize
by precalculating the lengths, using a technique that in Perl we call the &amp;quot;Schwartzian
transform&amp;quot;, and I&amp;#39;ll probably come back to this.
&lt;/p&gt;
&lt;p&gt;
OK, so we have a list of subsets to compare, now we need to find a dictionary of
canonical representations of words.  Luckily most unixy distributions ship with
one, often &lt;tt&gt;/usr/dict/words&lt;/tt&gt;, but Ubuntu sticks is elsewhere.
&lt;/p&gt;
&lt;p&gt;
I asked on #haskell, and was told I should use a &lt;tt&gt;Data.Map&lt;/tt&gt;, Haskell&amp;#39;s
basic equivalent of a hash or associative array, but implemented using a 
Functional Programming friendly tree representation.  In actual fact,
quicksilver, mrs, and mmorrow told me the answer straight away, but let&amp;#39;s
pretend for the purpose of this post that we&amp;#39;re working it out now :-)
&lt;/p&gt;
&lt;p&gt;
Assuming I load that
module, as is common, as &lt;tt&gt;M&lt;/tt&gt;, I&amp;#39;d essentially want to call
&lt;tt&gt;M.insertWith (++)&lt;/tt&gt; on each element.  The &lt;tt&gt;(++)&lt;/tt&gt; is the
concatenation operator, and it&amp;#39;s the right thing to use because the
dictionary is mapping &lt;tt&gt;String -&amp;gt; [String]&lt;/tt&gt;, for example

&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;tt&gt;fromList [(&amp;quot;admno&amp;quot;, [&amp;quot;nomad&amp;quot;,&amp;quot;monad&amp;quot;,&amp;quot;Damon&amp;quot;]),...]&lt;/tt&gt;&lt;/p&gt;&lt;/blockquote&gt;

&lt;em&gt;insertWith&lt;/em&gt; returns a new copy of the Map each time.  It&amp;#39;s like an accumulator
which gradually takes on the entries from the list of words.  And whenever we think
about accumulators, we can think about &lt;em&gt;fold&lt;/em&gt;s.

&lt;blockquote&gt;
&lt;pre&gt;foldl&amp;#39; (\m x -&amp;gt; M.insertWith (++) (canonicalize x) [x] m) mempty listOfWords&lt;/pre&gt;
&lt;/blockquote&gt;

&lt;em&gt;mempty&lt;/em&gt; is shorthand here for &amp;quot;an empty Data.Map&amp;quot;.  But we can go one better as
apparently fold/insertWith is so common that there is a shorthand, &lt;em&gt;fromListWith&lt;/em&gt;!

&lt;blockquote&gt;
&lt;pre&gt;fromListWith (++) . map (canonicalize &amp;amp;&amp;amp;&amp;amp; return)&lt;/pre&gt;
&lt;/blockquote&gt;
Woah!  That&amp;#39;s quite compact, and I just introduced some new syntax too:  The
&lt;tt&gt;&amp;amp;&amp;amp;&amp;amp;&lt;/tt&gt; is basically saying &amp;quot;let&amp;#39;s make a tuple with
the result of calling these 2 functions on my input!&amp;quot; so it&amp;#39;s the same as

&lt;blockquote&gt;
&lt;pre&gt;fromListWith (++) . map (\a -&amp;gt; (canonicalize a, return a))&lt;/pre&gt;
&lt;/blockquote&gt;

And &lt;em&gt;return&lt;/em&gt; just means &amp;quot;wrap this value in the appropriate Monad&amp;quot;.  So it&amp;#39;s
a scary way of saying &lt;tt&gt;[a]&lt;/tt&gt;, because we&amp;#39;re &amp;quot;in&amp;quot; the List monad.  (In the same way
that &lt;tt&gt;mempty&lt;/tt&gt; above was an empty Data.Map, because it was &amp;quot;in&amp;quot; the Map Monad.)

&lt;p&gt;
Whenever I play with Map, I get angry errors about the monomorphism restriction.
The way around that is to add an explicit type signature.  If, like me, you&amp;#39;re not
quite sure what to put there, you can add a compiler directive to quell the error,
then work out what the signature would be by calling &lt;tt&gt;:t my_function&lt;/tt&gt; from the
GHCI command line.  (You&amp;#39;ll often find afterwards that you can remove the signatures
if you wanted to, because later on the compiler has more information to work out the
types of things.  It&amp;#39;s only really &lt;em&gt;during&lt;/em&gt; incremental development that you
get the problem.

&lt;/p&gt;&lt;blockquote&gt;
&lt;pre&gt;{-# LANGUAGE NoMonomorphismRestriction #-}&lt;br /&gt;-- (that&amp;#39;s the compiler directive, you can comment this out later)&lt;br /&gt;&lt;br /&gt;makeAnag s = do&lt;br /&gt;    d &amp;lt;- dict&lt;br /&gt;    return $ take 4 $ getAnagrams s d&lt;br /&gt;&lt;br /&gt;dict = do file &amp;lt;- readFile &amp;quot;/etc/dictionaries-common/words&amp;quot;&lt;br /&gt;          return $ mkdict $ lines file&lt;br /&gt;&lt;br /&gt;mkdict :: [String] -&amp;gt; M.Map String [String]&lt;br /&gt;mkdict = M.fromListWith (++) . map (canonicalize &amp;amp;&amp;amp;&amp;amp; return) . filter longEnough&lt;br /&gt;&lt;br /&gt;longEnough = (&amp;gt;=3) . length&lt;/pre&gt;
&lt;/blockquote&gt;

As you can see, for all the perceived difficulty of doing IO in a pure language
like Haskell, it doesn&amp;#39;t seem all that hard in this simple case.  &lt;tt&gt;readFile&lt;/tt&gt;
reads the file, and &lt;tt&gt;lines&lt;/tt&gt; splits it into an array of lines.

&lt;p&gt;
The final thing is to check each powerset against the dictionary.
To extract the value, we use &lt;tt&gt;M.lookup&lt;/tt&gt;.  This function &lt;tt&gt;fail&lt;/tt&gt;s if it
can&amp;#39;t find a value.  So we could do
&lt;/p&gt;&lt;ul&gt;&lt;li&gt;For each powerset in the list
&lt;/li&gt;&lt;li&gt;Check if it&amp;#39;s present
&lt;/li&gt;&lt;li&gt;And add it to the list if so
&lt;/li&gt;&lt;/ul&gt;

Which of course we could do with the &lt;tt&gt;Maybe&lt;/tt&gt; type and a &lt;tt&gt;filter&lt;/tt&gt;.
But we want a list, and in the List type, failure is represented by an empty list
&lt;tt&gt;[]&lt;/tt&gt;.  So we can just map and we&amp;#39;d get something like:

&lt;blockquote&gt;&lt;pre&gt;[ [&amp;quot;anagram&amp;quot;], [], [], [&amp;quot;anagram 1&amp;quot;, &amp;quot;anagram 2&amp;quot;], [] ]&lt;/pre&gt;&lt;/blockquote&gt;

With an empty list for each failure.  We can use concatMap to join these together.  So it&amp;#39;s:

&lt;blockquote&gt;&lt;pre&gt;concatMap (\v -&amp;gt; M.lookup v dict) listOfPowersets&lt;/pre&gt;&lt;/blockquote&gt;

Though that actually returns:

&lt;blockquote&gt;&lt;pre&gt;[ [&amp;quot;anagram&amp;quot;], [&amp;quot;anagram 1&amp;quot;, &amp;quot;anagram 2&amp;quot;], ]&lt;/pre&gt;&lt;/blockquote&gt;

which I hadn&amp;#39;t expected.  (&lt;tt&gt;M.lookup&lt;/tt&gt; returned a list like &lt;tt&gt;[&amp;quot;anagram
1&amp;quot;, &amp;quot;anagram 2&amp;quot;]&lt;/tt&gt;.  
Quite literally it &lt;tt&gt;&lt;strong&gt;return&lt;/strong&gt;&lt;/tt&gt;ed it, which in List context means it
actually passed &lt;tt&gt;[[&amp;quot;anagram 1&amp;quot;, &amp;quot;anagram 2&amp;quot;]]&lt;/tt&gt;, which is why the list isn&amp;#39;t completely
flattened by concatMap.  I get around this by using &lt;tt&gt;join&lt;/tt&gt;.  This is another of those
monadic functions: in List context it does exactly what we want here, flattening this list.

&lt;blockquote&gt;
&lt;pre&gt;getAnagrams s d = join &lt;br /&gt;                . concatMap (flip M.lookup $ d)&lt;br /&gt;                $ filter longEnough  -- 3 or more letters&lt;br /&gt;                . sortBy (flip $ comparing length)  -- longest first&lt;br /&gt;                . nub                -- unique entries only&lt;br /&gt;                . powerset           -- all combinations of &lt;br /&gt;                . canonicalize       -- canonical (sorted) string&lt;br /&gt;                $ s&lt;/pre&gt;&lt;/blockquote&gt;
                
You can look at the final &lt;a href=&quot;http://greenokapi.net/svn/code/scratch/countdown.hs&quot;&gt;Haskell Countdown code&lt;/a&gt;.  I&amp;#39;ll look at optimizing the sort and the powersets soon, any comments on
other improvements (including better algorithms) very welcome.  (Sorry, comments require
Vox signup...)&lt;br /&gt;&lt;/p&gt;    &lt;p style=&quot;clear:both;&quot;&gt; 
    &lt;a href=&quot;http://osfameron.vox.com/library/post/countdown-words-game-solver-in-haskell.html?_c=feed-rss-full#comments&quot;&gt;Read and post comments&lt;/a&gt;   |   
    &lt;a href=&quot;http://www.vox.com/share/6a00c225240a9af21900fa968015b70003?_c=feed-rss-full&quot;&gt;Send to a friend&lt;/a&gt; 
&lt;/p&gt;
 
            </description> 
            <category domain="http://osfameron.vox.com/tags/">countdown</category> 
            <category domain="http://osfameron.vox.com/tags/">haskell</category>   
        </item> 
 
        <item>
            <title>Monads in Perl (take 1)</title>
            <link>http://osfameron.vox.com/library/post/monads-in-perl-take-1.html?_c=feed-rss-full</link>   
            <author>nobody@vox.com(osfameron)</author>
            <comments>http://osfameron.vox.com/library/post/monads-in-perl-take-1.html?_c=feed-rss-full</comments>
            <guid isPermaLink="true">http://osfameron.vox.com/library/post/monads-in-perl-take-1.html?_c=feed-rss-full</guid> 
            <pubDate>Thu, 12 Jun 2008 23:27:26 +0100</pubDate>         
            
            <description>    



&lt;p&gt;
I&amp;#39;ve been away for a while from Haskell so I thought I should do some revision
and really get my head around Monads.  While I plodded through the wonderful
&lt;a href=&quot;http://www.haskell.org/all_about_monads/html/meet.html&quot;&gt;&amp;quot;meet the monads&amp;quot; tutorial&lt;/a&gt;, I decided that the best way to learn would be to do.  By implementing Monads in Perl.
I&amp;#39;d highly recommend trying to implement monads in Your Favourite Language, if it
supports lambdas.  Perl has &lt;a href=&quot;http://sleepingsquirrel.org/monads/monads.html&quot;&gt; already been done by
Greg Buchholz&lt;/a&gt; and rather nicely too, but there&amp;#39;s no Monad library on CPAN
so I thought it would be worth a try.
&lt;/p&gt;

&lt;p&gt;
First of all, the question of how to model &amp;quot;types&amp;quot; is easily resolved.  We bless each
monad into the &lt;tt&gt;Monad&lt;/tt&gt; class or a subclass.  These can then have methods for
&lt;tt&gt;bind&lt;/tt&gt; and &lt;tt&gt;return&lt;/tt&gt; etc.
&lt;/p&gt;

&lt;p&gt;
Now I do like the haskell &lt;tt&gt;&amp;gt;&amp;gt;&lt;/tt&gt; and by a stroke of good fortune, Perl allows
us to overload that symbol too.

&lt;/p&gt;&lt;blockquote&gt;
&lt;pre&gt;use overload &amp;#39;&amp;gt;&amp;gt;&amp;#39;   =&amp;gt; &amp;#39;Bind&amp;#39;;&lt;/pre&gt;
&lt;/blockquote&gt;


&lt;p&gt;
I use the string &lt;tt&gt;&amp;#39;Bind&amp;#39;&lt;/tt&gt; rather than the reference &lt;tt&gt;\&amp;amp;Bind&lt;/tt&gt;, so that
the subclasses can easily override it.
&lt;/p&gt;

&lt;p&gt;
Some default bind methods in &lt;tt&gt;Monad.pm&lt;/tt&gt; and &lt;tt&gt;Monad::Maybe&lt;/tt&gt; etc.,
&lt;a href=&quot;http://greenokapi.net/svn/code/scratch/Monads/&quot;&gt;available here&lt;/a&gt; and
we have some simple examples like this one (in test.pl):

&lt;/p&gt;&lt;blockquote&gt;
&lt;pre&gt;my $result = &lt;br /&gt;      (Writer 2) &amp;gt;&amp;gt;&lt;br /&gt;      L { my $x = shift; (Writer $x*2, &amp;quot;Doubled. &amp;quot;) &amp;gt;&amp;gt;&lt;br /&gt;      L { my $y = shift; (Writer $y+1, &amp;quot;Plus 1. &amp;quot;)  &amp;gt;&amp;gt;&lt;br /&gt;      L { my $z = shift; (Writer $z*3, &amp;quot;Tripled $z. &amp;quot;) &lt;br /&gt;      }}};&lt;/pre&gt;
&lt;/blockquote&gt;


&lt;p&gt;
Woot!  OK, that&amp;#39;s not entirely beautiful, but it&amp;#39;s been slightly improved by the
overloading of &lt;tt&gt;&amp;gt;&amp;gt;&lt;/tt&gt;.
&lt;/p&gt;

&lt;p&gt;
The &lt;tt&gt;L&lt;/tt&gt; lambda generator is also there for readability.  It&amp;#39;s basically defined as

&lt;/p&gt;&lt;blockquote&gt;&lt;pre&gt;sub L (&amp;amp;) { shift }&lt;/pre&gt;&lt;/blockquote&gt;&lt;p&gt;

i.e. it&amp;#39;s an identity function, but it&amp;#39;s an L (like lambda) and to my mind, lined up on 
the left, it looks pleasingly like &amp;quot;and then&amp;quot;.


&lt;h2&gt;Nests&lt;/h2&gt;

&lt;p&gt;
This didn&amp;#39;t just fall straight out of the text editor into fully working code, of course.
A blow-by-blow account of me getting confused wouldn&amp;#39;t be especially interesting, but one
big &amp;quot;aha&amp;quot; moment is worth pointing out.  I realised that I was thinking of monads as being
a chain of lambdas, each one passing control to the next, like OO chaining:  
&lt;/p&gt;
    
    
    

    
    
    

    
    
    

    
    
    

    
    
    
&lt;div at:enclosure=&quot;asset&quot; at:xid=&quot;6a00c225240a9af21900fae8c2562a000b&quot; at:format=&quot;medium&quot; at:align=&quot;center&quot;
    class=&quot;enclosure enclosure-center enclosure-medium photo-enclosure&quot; 
     style=&quot;text-align: center;&quot;&gt;
&lt;div class=&quot;enclosure-inner&quot;
    
        style=&quot;padding: 9px; border: 1px solid; width: px; margin: 10px auto;&quot;
    &gt;
    &lt;div class=&quot;enclosure-list&quot;&gt;
        &lt;div class=&quot;enclosure-item photo-asset last&quot;&gt;
    
            &lt;div class=&quot;enclosure-image&quot;&gt;
        
                &lt;a href=&quot;http://osfameron.vox.com/library/photo/6a00c225240a9af21900fae8c2562a000b.html&quot;&gt;&lt;img src=&quot;http://a2.vox.com/6a00c225240a9af21900fae8c2562a000b-200pi&quot; alt=&quot;Chain of lambdas?&quot; title=&quot;Chain of lambdas?&quot; /&gt;&lt;/a&gt;
        
            &lt;/div&gt;
            &lt;div class=&quot;enclosure-meta&quot;&gt;
                &lt;div class=&quot;enclosure-asset-name&quot;&gt;&lt;a href=&quot;http://osfameron.vox.com/library/photo/6a00c225240a9af21900fae8c2562a000b.html&quot; title=&quot;Chain of lambdas?&quot;&gt;Chain of lambdas?&lt;/a&gt;&lt;/div&gt;
            &lt;/div&gt;
    
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;!-- end enclosure --&gt;




&amp;#160;

&lt;p&gt;
But that doesn&amp;#39;t work, as of course then the &lt;tt&gt;$x&lt;/tt&gt;, &lt;tt&gt;$y&lt;/tt&gt;,
&lt;tt&gt;$z&lt;/tt&gt; of each scope would be separate, whereas in fact, in &amp;quot;later&amp;quot; sections, you
can refer to &lt;tt&gt;$x&lt;/tt&gt; too.  This implies that the model is more like a nest of lambdas:
&lt;/p&gt;
    
    
    

    
    
    

    
    
    

    
    
    

    
    
    
&lt;div at:enclosure=&quot;asset&quot; at:xid=&quot;6a00c225240a9af21900fa967dc4a50002&quot; at:format=&quot;medium&quot; at:align=&quot;center&quot;
    class=&quot;enclosure enclosure-center enclosure-medium photo-enclosure&quot; 
     style=&quot;text-align: center;&quot;&gt;
&lt;div class=&quot;enclosure-inner&quot;
    
        style=&quot;padding: 9px; border: 1px solid; width: px; margin: 10px auto;&quot;
    &gt;
    &lt;div class=&quot;enclosure-list&quot;&gt;
        &lt;div class=&quot;enclosure-item photo-asset last&quot;&gt;
    
            &lt;div class=&quot;enclosure-image&quot;&gt;
        
                &lt;a href=&quot;http://osfameron.vox.com/library/photo/6a00c225240a9af21900fa967dc4a50002.html&quot;&gt;&lt;img src=&quot;http://a5.vox.com/6a00c225240a9af21900fa967dc4a50002-200pi&quot; alt=&quot;Nest of lambdas&quot; title=&quot;Nest of lambdas&quot; /&gt;&lt;/a&gt;
        
            &lt;/div&gt;
            &lt;div class=&quot;enclosure-meta&quot;&gt;
                &lt;div class=&quot;enclosure-asset-name&quot;&gt;&lt;a href=&quot;http://osfameron.vox.com/library/photo/6a00c225240a9af21900fa967dc4a50002.html&quot; title=&quot;Nest of lambdas&quot;&gt;Nest of lambdas&lt;/a&gt;&lt;/div&gt;
            &lt;/div&gt;
    
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;!-- end enclosure --&gt;




&amp;#160;

&lt;p&gt;
This is made fairly clear in the Perl above, with its delimited braces, if you look at
where the closing &amp;quot;&lt;tt&gt;}&lt;/tt&gt;&amp;quot; are, and which opening &amp;quot;&lt;tt&gt;{&lt;/tt&gt;&amp;quot; they match up with.
&lt;/p&gt;

&lt;p&gt;
This is an interesting mind shift, and one that I still haven&amp;#39;t really fully grasped, as
I&amp;#39;ll demonstrate a bit later.
&lt;/p&gt;

&lt;h2&gt; Polymorphic functions on monads &lt;/h2&gt;

&lt;p&gt;
In Haskell, you can call &amp;quot;&lt;tt&gt;return&lt;/tt&gt;&amp;quot; in a monadic block to &amp;quot;lift&amp;quot; a value to 
the appropriate monad.  Similarly, you can call &amp;quot;&lt;tt&gt;fail&lt;/tt&gt;&amp;quot;, and the function
will fail in the right way (returning &lt;tt&gt;Nothing&lt;/tt&gt; in a Maybe, throwing an error
in IO).  This is a function call, not a method, so how does it know which monad to
behave as?
&lt;/p&gt;

&lt;p&gt;
Of course Haskell does this with its strong inferencing typechecker.  The
compiler &amp;quot;knows&amp;quot; that we are in Maybe, so &amp;quot;fail&amp;quot; will be &lt;tt&gt;fail :: Maybe&lt;/tt&gt;.
&lt;/p&gt;

&lt;p&gt;
Perl on the other hand doesn&amp;#39;t have a strong type-inferencing compiler...
Right now I&amp;#39;m doing some shonky magic with &lt;tt&gt;caller()&lt;/tt&gt; that works in this
very simple test case (and I believe &lt;em&gt;only&lt;/em&gt; in this test case).  I think I
could just simplify things and set a dynamic variable &amp;quot;$Monad::current_monad&amp;quot;
on the first occurrence of &lt;tt&gt;Bind&lt;/tt&gt;.  Yeah, global variables, yuck.  The
final alternative that occurs to me would be to run the whole thing in a Reader
monad which just passes the name of the monad... but I&amp;#39;m fairly sure that&amp;#39;s
slightly insane.
&lt;/p&gt;

&lt;h2&gt; So what can it do right now? &lt;/h2&gt;

&lt;p&gt;
The &lt;a href=&quot;http://greenokapi.net/svn/code/scratch/Monads/test.pl&quot;&gt;test script&lt;/a&gt; shows
the current capabilities.  As of r246, I have Writer, Maybe, and List implemented (the
Monad superclass is effectively Identity).  
&lt;/p&gt;

&lt;p&gt;
I think Maybe is very useful - with some wrapper functions that raise Perl functions to
monadic ones using a variety of strategies (fail on undef/0/die etc.) it could be a useful
addition to the toolbox, simplifying a nested set of &lt;tt&gt;if&lt;/tt&gt; checks.
&lt;/p&gt;

&lt;p&gt;
The List monad already does list comprehensions, albeit with a rather yucky syntax.
Which is of course the big problem, &amp;#39;cos Perl programmers (and this statement may surprise
non Perl programmers :-) are often obsessive about syntax.
&lt;/p&gt;

&lt;h2&gt; Making it look pretty &lt;/h2&gt;

&lt;p&gt;
OK, so we already added a bit of sugar with the &lt;tt&gt;&amp;gt;&amp;gt;&lt;/tt&gt; overloading, and the
&lt;tt&gt;L&lt;/tt&gt; function for lambda generators, but it&amp;#39;s still rather ugly with the mix of
Perlish argument unpacking (&lt;tt&gt;my $x = shift&lt;/tt&gt;), scope delimiters (&lt;tt&gt;}}}&lt;/tt&gt;) etc.
&lt;/p&gt;

&lt;h3&gt; Source filters! &lt;/h3&gt;

&lt;p&gt;
The original &lt;a href=&quot;http://sleepingsquirrel.org/monads/monads.html&quot;&gt;Perl monad
tutorial&lt;/a&gt; used a source filter to give a monadic Do notation.  It&amp;#39;s a fairly
nice one as they go, but I don&amp;#39;t really want to treat my program as a string if
I can help it, so let&amp;#39;s look at some other techniques first!
&lt;/p&gt;

&lt;h3&gt; &lt;tt&gt;Devel::Declare&lt;/tt&gt; &lt;/h3&gt;

&lt;p&gt;
Matt Trout has been working on some crazy parsing magic in
&lt;tt&gt;&lt;a href=&quot;http://search.cpan.org/%7Emstrout/Devel-Declare/&quot;&gt;Devel::Declare&lt;/a&gt;&lt;/tt&gt;.
This isn&amp;#39;t a source filter, but (I think) hooks into Perl&amp;#39;s parser to change the way that
subroutine declarations are parsed.  It&amp;#39;d designed to give us parameter
unpacking, so that we could substitute:
&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;&lt;tt&gt;L {my $x = shift; .... }&lt;/tt&gt;&lt;/p&gt;&lt;/blockquote&gt;
with:
&lt;blockquote&gt;&lt;p&gt;&lt;tt&gt;L ($x) { .... }&lt;/tt&gt;&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;
In the current version this doesn&amp;#39;t work (you can define &lt;tt&gt;L&lt;/tt&gt; like that
easily, but the overloaded &lt;tt&gt;&amp;gt;&amp;gt;&lt;/tt&gt; evidences a minor parsing bug
(you&amp;#39;d have to put the expression between parentheses to get the precedence
right, which loses the syntactic advantage we gain).
&lt;/p&gt;

&lt;p&gt;
Still, hopefully will be fixed in a future release.
&lt;/p&gt;

&lt;h3&gt; Generators &lt;/h3&gt;

&lt;p&gt;
&amp;quot;Valued Lessons&amp;quot; has a beautiful post on &lt;a href=&quot;http://www.valuedlessons.com/2008/01/monads-in-python-with-nice-syntax.html&quot;&gt;Monads
in Python (with nice syntax!)&lt;/a&gt;.  The parenthesis is not hyperbole: the post describes
a monadic do block which looks about as pretty as Haskell&amp;#39;s, but which works in a different
way.  We spell &amp;#39;bind&amp;#39; (Haskell&amp;#39;s &lt;tt&gt;&amp;lt;-&lt;/tt&gt;) as &amp;#39;&lt;tt&gt;yield&lt;/tt&gt;&amp;#39;.  So a control sub
calls the &amp;#39;do&amp;#39; block, gets out monadic values one by one as they are &lt;tt&gt;yield&lt;/tt&gt;ed back,
and deals with the nitty gritty of &lt;tt&gt;bind&lt;/tt&gt;ing them to the rest of the generator.
&lt;/p&gt;

&lt;p&gt;
It took quite a while to understand the Python code: in fact I&amp;#39;m not sure I understand
it fully, I really don&amp;#39;t buy into the &amp;quot;Python is so easy to read&amp;quot; meme, and certainly
the &amp;quot;&lt;tt&gt;@whatever&lt;/tt&gt;&amp;quot; syntax, which seems to be &amp;#39;decorators&amp;#39; that modify the subroutine
that follows them, are rather confusing at first.  But it&amp;#39;s quite impressive, and it took
me a while to replicate in Perl.
&lt;/p&gt;

&lt;p&gt;
First hurdle:  Perl doesn&amp;#39;t have generators.  OK, that shouldn&amp;#39;t be an issue, I thought,
because we have the &lt;a href=&quot;http://search.cpan.org/&quot;&gt;CPAN&lt;/a&gt;.  And yes, I found Brock Wilcox&amp;#39;s
&lt;tt&gt;&lt;a href=&quot;http://search.cpan.org/%7Eawwaiid/Coro-Generator&quot;&gt;Coro::Generator&lt;/a&gt;&lt;/tt&gt;.
&lt;/p&gt;

&lt;p&gt;
This doesn&amp;#39;t quite do what I want though.  The yield only works one way, so

    &lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;tt&gt;my $x = yield (Monad 3);&lt;/tt&gt;&lt;/p&gt;&lt;/blockquote&gt;

doesn&amp;#39;t actually bind $x to 3.  I asked Brock on IRC, and apparently this behaviour is
desired (I&amp;#39;m not quite sure why) so I forked his code to play with it :-)
Also, the coroutine restarts immediately it finishes, which is inconvenient.
Brock suggested yielding undef at the end, which is fine, I can do that from the
control sub.
(The Python version deals with finishing by throwing an exception, so perhaps
it has the same semantics?)


&lt;p&gt;
After a lot of ugly pain, I finally got this working, and we can now do:

&lt;/p&gt;&lt;blockquote&gt;&lt;pre&gt;my $result = Do {&lt;br /&gt;    my $x = yield (Just 3);&lt;br /&gt;    my $y = yield (Nothing);&lt;br /&gt;    my $z = yield (Just 5);&lt;br /&gt;    warn &amp;quot;x=$x, y=$y, z=$z&amp;quot;;&lt;br /&gt;    Just 6;&lt;/pre&gt;&lt;/blockquote&gt;


&lt;p&gt;
Why the pain?  Failing to understand coroutines while trying to use them to implement monads
(which I understand only very slightly) was a bad start.  I found myself using the Do function
to repeatedly take a value from the generator and bind it with the next value (rather than
letting the monadic bind deal with those details).  And even when I&amp;#39;d realised that the
sub that I needed to bind was a lambda that would abstract the details of invoking the coroutine,
I still ended up flailing around more or less at random till I finally got it working.
&lt;/p&gt;

&lt;p&gt;
The current code is ugly (declared inline in &lt;tt&gt;test.pl&lt;/tt&gt; rather than modularized) but
the result is pleasantly magical and readable.
&lt;/p&gt;

&lt;p&gt;
Props of course to Python for having powerful techniques like &lt;tt&gt;yield&lt;/tt&gt; and decorators 
in core!
&lt;/p&gt;

&lt;h3&gt; Hold the champagne &lt;/h3&gt;

&lt;p&gt;
Of course the final test example, in the List monad doesn&amp;#39;t work.  Why?  The List monad&amp;#39;s
bind strategy is to call the function on every element of the list, so the coroutine will get
called repeatedly.  And every time it&amp;#39;s called, the execution pointer will move on.
&lt;/p&gt;

&lt;p&gt;
I wonder whether the Python version has the same problem?  I looked again at
the Coro modules on CPAN, and noted that they are advertised as being able to
implement &amp;quot;(non-clonable) continuations&amp;quot;.  I think this is the problem: I want to be
able to take the point at which the next Bind will be called, and call exactly that same
point multiple times (for the List monad).  I asked various people including Brock again,
and Scott Walters (the authors of &lt;a href=&quot;http://continuity.tlt42.org/&quot;&gt;Continuity, a
continuation-based web application framework in Perl&lt;/a&gt;) and got the answer that Perl
really doesn&amp;#39;t do proper continuations.  (As far as I understood it, they&amp;#39;re more or
less practically impossible, due to the way Perl models its execution context).
&lt;/p&gt;

&lt;p&gt;
So, unless I&amp;#39;ve misunderstood (and please let me know if I have!) this technique is
limited to monads that only call the bound function once (e.g. most of them except List).
That&amp;#39;s a shame though, as the List comprehension semantics would be lovely to express
in a monadic do block.
&lt;/p&gt;

&lt;h3&gt; Meta continuations &lt;/h3&gt;

&lt;p&gt;
The Valued Lesson post &lt;em&gt;does&lt;/em&gt; implement continuations monadically... Could we do that
and then implement monadic do using these monadic continuations?  I think the answer might be
&amp;quot;Yes but my brain would explode trying to implement it&amp;quot;.
&lt;/p&gt;

&lt;h3&gt; Plan &lt;tt&gt;B&lt;/tt&gt; &lt;/h3&gt;

&lt;p&gt;
I think that the most sensible method may be to take the contents of the monadic do
block and use the &lt;tt&gt;B::&lt;/tt&gt; modules to convert them from what &lt;em&gt;looks like&lt;/em&gt;
&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;tt&gt;my $x = bind ...;&lt;/tt&gt;&lt;/p&gt;&lt;/blockquote&gt; to 
&lt;blockquote&gt;&lt;p&gt;&lt;tt&gt;... &amp;gt;&amp;gt; sub { my $x = shift;&lt;/tt&gt;&lt;/p&gt;&lt;/blockquote&gt;.  Which
is pretty much the approach of Greg Buchholz&amp;#39;s source filter.  But I think a parse
tree transformation may be more elegant.  (This said, I don&amp;#39;t know the Perl source
or understand the opcodes, so it may just be slightly crazy).&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Update: &lt;/strong&gt;Some &lt;a href=&quot;http://www.reddit.com/r/programming/info/6n5wt/comments/&quot;&gt;discussion on reddit&lt;/a&gt;, as Vox still doesn&amp;#39;t support OpenID&lt;br /&gt;

&lt;/p&gt;    &lt;p style=&quot;clear:both;&quot;&gt; 
    &lt;a href=&quot;http://osfameron.vox.com/library/post/monads-in-perl-take-1.html?_c=feed-rss-full#comments&quot;&gt;Read and post comments&lt;/a&gt;   |   
    &lt;a href=&quot;http://www.vox.com/share/6a00c225240a9af21900fad690d9cd0004?_c=feed-rss-full&quot;&gt;Send to a friend&lt;/a&gt; 
&lt;/p&gt;
 
            </description> 
            <category domain="http://osfameron.vox.com/tags/">perl</category> 
            <category domain="http://osfameron.vox.com/tags/">haskell</category> 
            <category domain="http://osfameron.vox.com/tags/">monads</category> 
            <category domain="http://osfameron.vox.com/tags/">lambdacamel</category>    
        </item> 
 
        <item>
            <title>&quot;Readable Perl&quot; talk slides up</title>
            <link>http://osfameron.vox.com/library/post/readable-perl-talk-slides-up.html?_c=feed-rss-full</link>   
            <author>nobody@vox.com(osfameron)</author>
            <comments>http://osfameron.vox.com/library/post/readable-perl-talk-slides-up.html?_c=feed-rss-full</comments>
            <guid isPermaLink="true">http://osfameron.vox.com/library/post/readable-perl-talk-slides-up.html?_c=feed-rss-full</guid> 
            <pubDate>Thu, 29 May 2008 09:28:43 +0100</pubDate>         
            
            <description>    &lt;p&gt;Thanks to Chris and Thom for organising the recent &lt;a href=&quot;http://upcoming.yahoo.com/event/691199/&quot;&gt;GeekUp Liverpool talks&lt;/a&gt;.&amp;#160; The evening started well with Martin Owen&amp;#39;s very interesting talk on justifying Erlang, and why FP is going to become a major factor in tomorrow&amp;#39;s concurrency-oriented world.&amp;#160; I demonstrated the wisdom of &lt;strong&gt;always saving a copy of your talk in PDF to a FAT formatted USB drive&lt;/strong&gt; by being able to seamlessly present from Martin&amp;#39;s laptop when my own decided that it really wanted to do a fsck right now, thanks very much.&lt;/p&gt;&lt;p&gt;My talk went well, thanks in no small part to a very receptive and welcoming audience (largely non-Perl programmers).&amp;#160; I&amp;#39;ve now posted the slides to &lt;a href=&quot;http://greenokapi.net/talks/ReadablePerl.pdf&quot;&gt;http://greenokapi.net/talks/ReadablePerl.pdf&lt;/a&gt; under a Creative Commons Attribution-Non-Commercial 2.0 UK: England &amp;amp; Wales license.&amp;#160; Comments and questions welcome!&lt;/p&gt;&lt;p&gt;A varied discussion ensured, spanning legacy code, the value (or not) of training, vitamins and handmade chess-sets, Liverpool city of cultcha, and much much more.&lt;/p&gt;    &lt;p style=&quot;clear:both;&quot;&gt; 
    &lt;a href=&quot;http://osfameron.vox.com/library/post/readable-perl-talk-slides-up.html?_c=feed-rss-full#comments&quot;&gt;Read and post comments&lt;/a&gt;   |   
    &lt;a href=&quot;http://www.vox.com/share/6a00c225240a9af21900fa9679f2d30003?_c=feed-rss-full&quot;&gt;Send to a friend&lt;/a&gt; 
&lt;/p&gt;
 
            </description> 
            <category domain="http://osfameron.vox.com/tags/">perl</category> 
            <category domain="http://osfameron.vox.com/tags/">talk</category> 
            <category domain="http://osfameron.vox.com/tags/">liverpool</category> 
            <category domain="http://osfameron.vox.com/tags/">geekup</category>   
        </item> 
 
        <item>
            <title>Vista hate</title>
            <link>http://osfameron.vox.com/library/post/vista-hate.html?_c=feed-rss-full</link>   
            <author>nobody@vox.com(osfameron)</author>
            <comments>http://osfameron.vox.com/library/post/vista-hate.html?_c=feed-rss-full</comments>
            <guid isPermaLink="true">http://osfameron.vox.com/library/post/vista-hate.html?_c=feed-rss-full</guid> 
            <pubDate>Mon, 26 May 2008 22:11:59 +0100</pubDate>         
            
            <description>    &lt;p&gt;I&amp;#39;m currently suffering Vista to try to install some development software - on the one hand, for work, and on the other, to play with F# and dotNet.&lt;/p&gt;&lt;p&gt;I realised that I need the full version of Visual Studio (the free &amp;quot;Express&amp;quot; version doesn&amp;#39;t allow any plugins, by design) so downloaded the 90-day trial version.&amp;#160; It downloads as a .iso file to burn to disk, or to mount.&lt;/p&gt;&lt;p&gt;Cunningly, Vista doesn&amp;#39;t have any builtin tools to do anything with a .iso.&amp;#160; Now, I&amp;#39;m getting used to Windows not having basic functionality that you could just take for granted under Linux or Mac, but this is pretty silly for software downloaded from Microsoft itself.&lt;/p&gt;&lt;p&gt;A quick google for &amp;quot;mount iso free vista&amp;quot; came up with a few aborted attempts (XP only, non-free, etc.) and finally, this: &lt;a href=&quot;http://www.slysoft.com/en/download.html&quot;&gt;Virtual CloneDrive, from SlySoft&lt;/a&gt; which so far seems to pleasantly Just Work.&lt;br /&gt; &lt;/p&gt;    &lt;p style=&quot;clear:both;&quot;&gt; 
    &lt;a href=&quot;http://osfameron.vox.com/library/post/vista-hate.html?_c=feed-rss-full#comments&quot;&gt;Read and post comments&lt;/a&gt;   |   
    &lt;a href=&quot;http://www.vox.com/share/6a00c225240a9af21900fad68b94570004?_c=feed-rss-full&quot;&gt;Send to a friend&lt;/a&gt; 
&lt;/p&gt;
 
            </description> 
            <category domain="http://osfameron.vox.com/tags/">windows</category> 
            <category domain="http://osfameron.vox.com/tags/">vista</category> 
            <category domain="http://osfameron.vox.com/tags/">hate</category> 
            <category domain="http://osfameron.vox.com/tags/">iso</category>   
        </item> 
 
        <item>
            <title>More Liverpool talks: Perl, Erlang</title>
            <link>http://osfameron.vox.com/library/post/more-liverpool-talks-perl-erlang.html?_c=feed-rss-full</link>   
            <author>nobody@vox.com(osfameron)</author>
            <comments>http://osfameron.vox.com/library/post/more-liverpool-talks-perl-erlang.html?_c=feed-rss-full</comments>
            <guid isPermaLink="true">http://osfameron.vox.com/library/post/more-liverpool-talks-perl-erlang.html?_c=feed-rss-full</guid> 
            <pubDate>Fri, 16 May 2008 15:31:39 +0100</pubDate>         
            
            <description>    &lt;p&gt;Thom has posted the details of the next &lt;a href=&quot;http://upcoming.yahoo.com/event/691199/&quot;&gt;Liverpool geekup&lt;/a&gt;, Tuesday May 27th at 3345 Parr Street. &lt;br /&gt;Last time, I admitted to programming in Perl and got ribbed about it being unreadable.&amp;#160; Fueled by the fervour of the righteous (and maybe a pint or two of Cains bitter) I volunteered to do a talk on Readable Perl.&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;People like to claim Perl is line noise, with its sigils and regular
expressions. But a lot of the features that make it possible to write,
yes, truly awful, unreadable Perl, also let you write clean,
maintainable code too.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;
    those $%&amp;amp;* sigils!&lt;/li&gt;&lt;li&gt;there&amp;#39;s More Than One Way To Do It&lt;/li&gt;&lt;li&gt;
    strings and data structures&lt;/li&gt;&lt;li&gt;
    map, grep, first class functions&lt;/li&gt;&lt;li&gt;
    metaprogramming and the CPAN&lt;/li&gt;&lt;li&gt;modern Object Oriented programming with Moose &lt;/li&gt;&lt;/ul&gt;&lt;/blockquote&gt;&lt;p&gt;Martin Owen will also be talking on Erlang, which I&amp;#39;m very much looking forward to!&lt;/p&gt;&lt;p&gt;Hope to see you there :-) &lt;/p&gt;    &lt;p style=&quot;clear:both;&quot;&gt; 
    &lt;a href=&quot;http://osfameron.vox.com/library/post/more-liverpool-talks-perl-erlang.html?_c=feed-rss-full#comments&quot;&gt;Read and post comments&lt;/a&gt;   |   
    &lt;a href=&quot;http://www.vox.com/share/6a00c225240a9af21900fae8b9e0ad000b?_c=feed-rss-full&quot;&gt;Send to a friend&lt;/a&gt; 
&lt;/p&gt;
 
            </description> 
            <category domain="http://osfameron.vox.com/tags/">perl</category> 
            <category domain="http://osfameron.vox.com/tags/">liverpool</category> 
            <category domain="http://osfameron.vox.com/tags/">geekup</category> 
            <category domain="http://osfameron.vox.com/tags/">erlang</category>   
        </item> 
 
        <item>
            <title>F# talk in Liverpool</title>
            <link>http://osfameron.vox.com/library/post/f-talk-in-liverpool.html?_c=feed-rss-full</link>   
            <author>nobody@vox.com(osfameron)</author>
            <comments>http://osfameron.vox.com/library/post/f-talk-in-liverpool.html?_c=feed-rss-full</comments>
            <guid isPermaLink="true">http://osfameron.vox.com/library/post/f-talk-in-liverpool.html?_c=feed-rss-full</guid> 
            <pubDate>Fri, 16 May 2008 08:35:07 +0100</pubDate>         
            
            <description>    &lt;p&gt;
I&amp;#39;d been out of Liverpool for 3 years or so, and I completely missed &lt;a href=&quot;http://geekup.org/&quot;&gt;GeekUp&lt;/a&gt;: a loosely
affiliated, grassroots tech meetup society in the North West.  The Liverpool branch is
pretty active, and linked with various other groups, such as the 
&lt;a href=&quot;http://liverpool.usersof.net/&quot;&gt;DotNet user group&lt;/a&gt;,
where &lt;a href=&quot;http://blog.cwa.me.uk/&quot;&gt;Chris Alcock&lt;/a&gt; gave a very interesting
&lt;a href=&quot;http://upcoming.yahoo.com/event/547197/&quot;&gt;talk on F#&lt;/a&gt;.

&lt;/p&gt;&lt;p&gt;
Not sure what the Dot Net programmers made of it, there were some questions afterwards
amounting to &amp;quot;What&amp;#39;s the point?  Are academics going to use it?&amp;quot; :-)  Which I thought
was amusing as I was looking at it from the perspective of a Haskell newbie, thinking
a) that&amp;#39;s cool, b) it&amp;#39;s simpler than Haskell, c) it plugs into the .Net libraries and
development environment, and had concluded that it could (possibly) become a massive hit
in real-world programming too...

&lt;/p&gt;&lt;p&gt;
Some notes, mainly comparisons with Haskell:

&lt;/p&gt;&lt;ul&gt;&lt;li&gt; The &lt;tt&gt;#light&lt;/tt&gt; pragma adds syntactic sugar, very much like the
Haskell &lt;tt&gt;do&lt;/tt&gt; notation.  (No need for open/close/statement delimiters,
whitespace significant, skip &lt;tt&gt;in&lt;/tt&gt; off &lt;tt&gt;let&lt;/tt&gt; statements)
&lt;/li&gt;&lt;li&gt; The REPL is multiline by default (dons on #haskell noted that ghci
supports this with &lt;tt&gt;:{&lt;/tt&gt;
&lt;/li&gt;&lt;li&gt; Functions aren&amp;#39;t recursive by default and have to be introduced as such (&lt;tt&gt;let &lt;em&gt;rec&lt;/em&gt; factorial = ...&lt;/tt&gt;)
&lt;/li&gt;&lt;li&gt; &lt;tt&gt;List&lt;/tt&gt;s aren&amp;#39;t lazy, but there&amp;#39;s a &lt;em&gt;separate&lt;/em&gt; datatype called &lt;tt&gt;Seq&lt;/tt&gt; which is.
&lt;/li&gt;&lt;li&gt; You can use &lt;tt&gt;yield&lt;/tt&gt; in a function to define lazy sequences.
&lt;/li&gt;&lt;li&gt; Like Ocaml, F# supports &lt;tt&gt;mutable&lt;/tt&gt; data, though the default is pure data.
&lt;/li&gt;&lt;li&gt; It also supports reference types - I&amp;#39;m not sure I understand what these
are for in a functional programming language, or if they&amp;#39;re just for updating,
then how they&amp;#39;re different from plain old mutable data.  The example Chris gave
was the classic closure example of a counter function.
&lt;/li&gt;&lt;li&gt;
    
    
    










    
    
    









&lt;div at:enclosure=&quot;asset&quot; at:xid=&quot;6a00c225240a9af21900fa9675da910003&quot; at:format=&quot;small&quot; at:align=&quot;right&quot;
    class=&quot;enclosure enclosure-right enclosure-small book-enclosure&quot; 
     style=&quot;text-align: center; float: right;&quot;&gt;
&lt;div class=&quot;enclosure-inner&quot;
    
        style=&quot;padding: 9px; border: 1px solid; width: px; margin: 0 0 20px 20px;&quot;
    &gt;
    &lt;div class=&quot;enclosure-list&quot;&gt;
        &lt;div class=&quot;enclosure-item book-asset last&quot;&gt;
    
            &lt;div class=&quot;enclosure-image&quot;&gt;
        
                &lt;a href=&quot;http://osfameron.vox.com/library/book/6a00c225240a9af21900fa9675da910003.html&quot;&gt;&lt;img src=&quot;http://a1.vox.com/6a00c225240a9af21900fa9675da910003-120pi&quot; alt=&quot;Expert F# Hardback (Expert&#39;s Voice in .Net)&quot; title=&quot;Expert F# Hardback (Expert&#39;s Voice in .Net)&quot; /&gt;&lt;/a&gt;
        
            &lt;/div&gt;
            &lt;div class=&quot;enclosure-meta&quot;&gt;
                &lt;div class=&quot;enclosure-asset-name&quot;&gt;&lt;a href=&quot;http://osfameron.vox.com/library/book/6a00c225240a9af21900fa9675da910003.html&quot; title=&quot;Expert F# Hardback (Expert&#39;s Voice in .Net)&quot;&gt;Expert F# Hardback (Expert&#39;s Voice in .Net)&lt;/a&gt;&lt;/div&gt;
            &lt;/div&gt;
    
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;!-- end enclosure --&gt;

 The examples he made of pipelining with &lt;tt&gt;|&amp;gt;&lt;/tt&gt; and &lt;tt&gt;&amp;gt;&amp;gt;&lt;/tt&gt;
looked very much Haskellish monads (especially in a &lt;tt&gt;#light&lt;/tt&gt; style
block).  I quickly leafed through Chris&amp;#39;s copy of
till I found the
section on monads.  They&amp;#39;re called &amp;quot;Workflows&amp;quot;, because that&amp;#39;s less scary than
Monads.  They&amp;#39;re also largely transparent, which on one hand is nice, as
there&amp;#39;s none of the painful and ugly &amp;quot;lifting&amp;quot; of values to the appropriate
monad.  (On the other, it means that you can&amp;#39;t easily separate action and
non-action code).  
&lt;/li&gt;&lt;li&gt; This of course means that you don&amp;#39;t get some of the benefits of FP&amp;#39;s
purity.  &lt;a href=&quot;http://blog.martinowen.net/&quot;&gt;Martin Owen&lt;/a&gt;, who is keen
on Erlang and its capacity for massively scalable, high performance networking,
also pointed out that allowing mutability means that you can&amp;#39;t guarantee that
the application is threadsafe, and is the wrong default as we&amp;#39;re coming up against
multicore programming.
&lt;/li&gt;&lt;/ul&gt;

&lt;p&gt;
All in all, it was a very interesting talk, and I&amp;#39;m looking forward to playing
with F#.  I apt-got &lt;a href=&quot;http://www.mono-project.com/Main_Page&quot;&gt;Mono&lt;/a&gt;, and
promptly failed to install F# on it, as the provided install.sh script whined about
something to do with &lt;tt&gt;gac&lt;/tt&gt; and &lt;tt&gt;aot&lt;/tt&gt;.  Ah well, perhaps that&amp;#39;s a good
excuse to boot up into Windows...
&lt;/p&gt;     &lt;p style=&quot;clear:both;&quot;&gt; 
    &lt;a href=&quot;http://osfameron.vox.com/library/post/f-talk-in-liverpool.html?_c=feed-rss-full#comments&quot;&gt;Read and post comments&lt;/a&gt;   |   
    &lt;a href=&quot;http://www.vox.com/share/6a00c225240a9af21900fad6884a750004?_c=feed-rss-full&quot;&gt;Send to a friend&lt;/a&gt; 
&lt;/p&gt;
 
            </description> 
            <category domain="http://osfameron.vox.com/tags/">dotnet</category> 
            <category domain="http://osfameron.vox.com/tags/">mono</category> 
            <category domain="http://osfameron.vox.com/tags/">liverpool</category> 
            <category domain="http://osfameron.vox.com/tags/">geekup</category> 
            <category domain="http://osfameron.vox.com/tags/">haskell</category> 
            <category domain="http://osfameron.vox.com/tags/">f#</category> 
            <category domain="http://osfameron.vox.com/tags/">ocaml</category> 
            <category domain="http://osfameron.vox.com/tags/">erlang</category> 
            <category domain="http://osfameron.vox.com/tags/">monads</category>    
        </item> 
    </channel>
</rss>

