<?xml version='1.0' encoding='utf-8' ?>
<!--  If you are running a bot please visit this policy page outlining rules you must respect. http://www.livejournal.com/bots/  -->
<rss version='2.0' xmlns:lj='http://www.livejournal.org/rss/lj/1.0/' xmlns:media='http://search.yahoo.com/mrss/' xmlns:atom10='http://www.w3.org/2005/Atom'>
<channel>
  <title>Benjamin Smith</title>
  <link>http://bs338.livejournal.com/</link>
  <description>Benjamin Smith - LiveJournal.com</description>
  <lastBuildDate>Tue, 19 Dec 2006 20:14:31 GMT</lastBuildDate>
  <generator>LiveJournal / LiveJournal.com</generator>
  <lj:journal>bs338</lj:journal>
  <lj:journalid>11524928</lj:journalid>
  <lj:journaltype>personal</lj:journaltype>
  <atom10:link rel='hub' href='http://pubsubhubbub.appspot.com/' />
  <image>
    <url>http://l-userpic.livejournal.com/54441878/11524928</url>
    <title>Benjamin Smith</title>
    <link>http://bs338.livejournal.com/</link>
    <width>100</width>
    <height>99</height>
  </image>

<item>
  <guid isPermaLink='true'>http://bs338.livejournal.com/687.html</guid>
  <pubDate>Tue, 19 Dec 2006 20:14:31 GMT</pubDate>
  <title>Hiding general recursion inside a monad</title>
  <link>http://bs338.livejournal.com/687.html</link>
  <description>&lt;p&gt;I’ve been thinking a bit about using a monad to hide general recursion.  By hide, I mean that you cannot construct a function &lt;i&gt;fix&lt;/i&gt; with type (∀a. (a -&amp;gt; a) -&amp;gt; a).  The first monad I tried was basically a reader monad with a run function that just used fix.  Needless to say this &lt;a href=&quot;http://svn.cabbage.org.uk/svn/snippets/recmonad/RecBroken.hs&quot;&gt;doesn’t hide the recursion&lt;/a&gt;.  My next attempt is more successful and has the &lt;a href=&quot;http://svn.cabbage.org.uk/svn/snippets/recmonad/Rec.hs&quot;&gt;interface&lt;/a&gt; below:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;data Rec a b
instance Monad (Rec a)
instance MonadReader a (Rec a)
recurse :: a -&amp;gt; Rec a a
runRec :: a -&amp;gt; Rec a a -&amp;gt; a
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And here’s an example of using it to write a fibonacci function.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;-- Fibonacci sequence
fib :: Integer -&amp;gt; Integer
fib n = runRec n $ do
  n &amp;lt;- ask
  case n of
    0 -&amp;gt; return 0
    1 -&amp;gt; return 1
    _ -&amp;gt; do
      x &amp;lt;- recurse (n-2)
      y &amp;lt;- recurse (n-1)
      return (x + y)
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The next thing I want to try is to prove that you can’t construct &lt;i&gt;fix&lt;/i&gt;.  I guess my argument would start need to start off with looking at runRec and where I’m going to get something for its first argument.&lt;/p&gt;</description>
  <comments>http://bs338.livejournal.com/687.html</comments>
  <category>computer science</category>
  <category>monads</category>
  <category>haskell</category>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>http://bs338.livejournal.com/416.html</guid>
  <pubDate>Thu, 14 Dec 2006 21:17:56 GMT</pubDate>
  <title>Chemical computing</title>
  <link>http://bs338.livejournal.com/416.html</link>
  <description>&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;http://www.inria.fr/rrrt/rr-5743.html&quot;&gt;&quot;Generalized Multisets for Chemical Programming&quot;&lt;/a&gt;, Banâtre, Fradet, Radenac.&lt;/li&gt;
  &lt;li&gt;And accompanying &lt;a href=&quot;http://upp.lami.univ-evry.fr/Documents/Radenac-Slides-UPP&amp;#39;04.pdf&quot;&gt;slides&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;i&gt;[pointed out by rgs in #perl6]&lt;/i&gt;&lt;/p&gt;</description>
  <comments>http://bs338.livejournal.com/416.html</comments>
  <category>physics</category>
  <category>computation</category>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
</channel>
</rss>
