<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Melding Monads &#187; queues</title>
	<atom:link href="http://blog.melding-monads.com/category/queues/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.melding-monads.com</link>
	<description>Math, Computer Science,  and Education</description>
	<lastBuildDate>Thu, 22 Jul 2010 01:19:29 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='blog.melding-monads.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/00697c715d31ef0ea311be464c12e163?s=96&#038;d=http://s2.wp.com/i/buttonw-com.png</url>
		<title>Melding Monads &#187; queues</title>
		<link>http://blog.melding-monads.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://blog.melding-monads.com/osd.xml" title="Melding Monads" />
	<atom:link rel='hub' href='http://blog.melding-monads.com/?pushpress=hub'/>
		<item>
		<title>Control.Monad.Queue</title>
		<link>http://blog.melding-monads.com/2009/06/22/control-monad-queue/</link>
		<comments>http://blog.melding-monads.com/2009/06/22/control-monad-queue/#comments</comments>
		<pubDate>Tue, 23 Jun 2009 01:41:35 +0000</pubDate>
		<dc:creator>lpsmith</dc:creator>
				<category><![CDATA[continuations]]></category>
		<category><![CDATA[corecursion]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[monads]]></category>
		<category><![CDATA[queues]]></category>

		<guid isPermaLink="false">http://blog.melding-monads.com/?p=92</guid>
		<description><![CDATA[Haskell aficionados, take note! My library for corecursive queues has now been uploaded to Hackage. You can now cabal-install it. I also have a substantially revised draft of the associated paper, Lloyd Allison&#8217;s Corecursive Queues, available. It has been re-organized so that it is hopefully easier to follow, it includes a careful performance comparison, and [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.melding-monads.com&blog=6077169&post=92&subd=meldingmonads&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>Haskell aficionados, take note!  My library for <a href="http://hackage.haskell.org/package/control-monad-queue">corecursive queues</a> has now been uploaded to Hackage.   You can now cabal-install it.</p>
<p>I also have a substantially revised draft  of the associated paper,  <a href="http://meldingmonads.files.wordpress.com/2009/06/corecqueues.pdf">Lloyd Allison&#8217;s Corecursive Queues</a>,  available.   It has been re-organized so that it is hopefully easier to follow,   it includes a careful performance comparison,  and a tentative proof that <code>mapCont</code> cannot be expressed in terms of <code>callCC</code>,  <code>(&gt;&gt;=)</code>,  <code>return</code>.</p>
<p>The library includes a somewhat crude micro-benchmarking program in the <code>tests/</code> directory.   Those who have read previous drafts,  be warned that the few brief statements about performance were based on past notes,  and I found some several issues with the testing methodology contained in the notes.   Here the revised results:</p>
<table border="0" rules="cols">
<tbody>
<tr>
<th align="left">Description</th>
<th colspan="2">Time (ms)</th>
<th colspan="2">-H500M</th>
<th>Bytes allocated</th>
</tr>
<tr>
<th align="left">GHC 6.10.3</th>
<th align="center">mean</th>
<th align="center">σ</th>
<th align="center">mean</th>
<th align="center">σ</th>
<th align="center">per Branch</th>
</tr>
<tr>
<td>levelOrder&#8217;</td>
<td align="right">446</td>
<td align="right">5</td>
<td align="right">172</td>
<td align="right">15</td>
<td align="right">44.0</td>
</tr>
<tr>
<td>CorecQ</td>
<td align="right">555</td>
<td align="right">5</td>
<td align="right">619</td>
<td align="right">4</td>
<td align="right">133.5</td>
</tr>
<tr>
<td>CorecQW _</td>
<td align="right">696</td>
<td align="right">5</td>
<td align="right">1128</td>
<td align="right">6</td>
<td align="right">213.6</td>
</tr>
<tr>
<td>CorecQW ()</td>
<td align="right">907</td>
<td align="right">56</td>
<td align="right">2235</td>
<td align="right">11</td>
<td align="right">213.6</td>
</tr>
<tr>
<td>Side Channel _</td>
<td align="right">959</td>
<td align="right">3</td>
<td align="right">1171</td>
<td align="right">7</td>
<td align="right">228.7</td>
</tr>
<tr>
<td>Side Channel ()</td>
<td align="right">1500</td>
<td align="right">56</td>
<td align="right">2171</td>
<td align="right">7</td>
<td align="right">276.4</td>
</tr>
<tr>
<td>STQ</td>
<td align="right">1140</td>
<td align="right">8</td>
<td align="right">1087</td>
<td align="right">14</td>
<td align="right">371.2</td>
</tr>
<tr>
<td>TwoStack</td>
<td align="right">1158</td>
<td align="right">4</td>
<td align="right">778</td>
<td align="right">10</td>
<td align="right">185.8</td>
</tr>
<tr>
<td>Okasaki</td>
<td align="right">1553</td>
<td align="right">7</td>
<td align="right">1574</td>
<td align="right">12</td>
<td align="right">209.0</td>
</tr>
<tr>
<td>Data.Sequence</td>
<td align="right">962</td>
<td align="right">5</td>
<td align="right">1308</td>
<td align="right">5</td>
<td align="right">348.1</td>
</tr>
<tr>
<th align="left">GHC 6.8.3</th>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>levelOrder&#8217;</td>
<td align="right">461</td>
<td align="right">2</td>
<td align="right">173</td>
<td align="right">15</td>
<td align="right">44.1</td>
</tr>
<tr>
<td>CorecQ</td>
<td align="right">458</td>
<td align="right">4</td>
<td align="right">267</td>
<td align="right">13</td>
<td align="right">67.5</td>
</tr>
<tr>
<td>CorecQW _</td>
<td align="right">526</td>
<td align="right">5</td>
<td align="right">713</td>
<td align="right">5</td>
<td align="right">141.2</td>
</tr>
<tr>
<td>CorecQW ()</td>
<td align="right">781</td>
<td align="right">62</td>
<td align="right">1775</td>
<td align="right">62</td>
<td align="right">141.3</td>
</tr>
</tbody>
</table>
<p>These benchmarks come from performing breadth-first traversals repeatedly on the 34th fibonacci tree,  on an Intel Core 2 Duo T9550.   The first few data points were discarded,  and the mean and standard deviation of the remaining times were computed.    Note that <code>getCPUTime</code> was used to time each run,  and this has a resolution of only 10 milliseconds.</p>
<p>If you would like to play with the queue transformer,  which doesn&#8217;t appear in the library,  or other bits of code exactly as they appear in the paper,  you can download the source code <a href="http://www.melding-monads.com/CorecQueues.hs">here</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/meldingmonads.wordpress.com/92/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/meldingmonads.wordpress.com/92/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/meldingmonads.wordpress.com/92/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/meldingmonads.wordpress.com/92/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/meldingmonads.wordpress.com/92/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/meldingmonads.wordpress.com/92/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/meldingmonads.wordpress.com/92/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/meldingmonads.wordpress.com/92/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/meldingmonads.wordpress.com/92/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/meldingmonads.wordpress.com/92/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.melding-monads.com&blog=6077169&post=92&subd=meldingmonads&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://blog.melding-monads.com/2009/06/22/control-monad-queue/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e62561db40e46118628b31cba87840d6?s=96&#38;d=http%3A%2F%2Fs0.wp.com%2Fi%2Fmu.gif&#38;r=PG" medium="image">
			<media:title type="html">lpsmith</media:title>
		</media:content>
	</item>
		<item>
		<title>Lloyd Allison&#8217;s Corecursive Queues</title>
		<link>http://blog.melding-monads.com/2009/03/09/lloyd-allisons-corecursive-queues/</link>
		<comments>http://blog.melding-monads.com/2009/03/09/lloyd-allisons-corecursive-queues/#comments</comments>
		<pubDate>Mon, 09 Mar 2009 21:34:03 +0000</pubDate>
		<dc:creator>lpsmith</dc:creator>
				<category><![CDATA[continuations]]></category>
		<category><![CDATA[corecursion]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[monads]]></category>
		<category><![CDATA[queues]]></category>

		<guid isPermaLink="false">http://blog.melding-monads.com/?p=5</guid>
		<description><![CDATA[I&#8217;m proud to announce that a draft of the release of my paper, &#8220;Lloyd Allison&#8217;s Corecursive Queues: Why Continuations Matter&#8220;, is now available. (Source code available here, with a hackage package soon to come available here) Wouter Swierstra has informed me that he will publish it in the Monad Reader. However, it will appear in [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.melding-monads.com&blog=6077169&post=5&subd=meldingmonads&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m proud to announce <s>that a draft of</s> the release of my paper,  &#8220;<a href="http://themonadreader.files.wordpress.com/2009/07/issue142.pdf">Lloyd Allison&#8217;s Corecursive Queues:  Why Continuations Matter</a>&#8220;,  is now available.  (Source code available <a href="http://www.melding-monads.com/CorecQueues.hs">here</a>,  with a hackage package <s>soon to come</s> <a href="http://hackage.haskell.org/package/control-monad-queue">available here</a>)  Wouter Swierstra has informed me that he will publish it in the <a href="http://www.haskell.org/haskellwiki/The_Monad.Reader">Monad Reader</a>.   However,  it will appear in the next issue after the upcoming one,  due to an unexpectedly large number of submissions this time around.  Here is the abstract:</p>
<blockquote><p>
In a purely functional setting,  real-time queues are traditionally thought to be much harder to implement than either real-time stacks or amortized O(1) queues.  In &#8220;<a href="http://www.csse.monash.edu.au/~lloyd/tildeFP/1989SPE/">Circular Programs and Self-Referential Structures</a>,&#8221;  Lloyd Allison uses <i>corecursion</i> to implement a queue by defining a lazy list in terms of itself.   This provides a simple,  efficient, and attractive implementation of real-time queues.</p>
<p>While Allison&#8217;s queues are general, in the sense it is straightforward to adapt  his technique to a new algorithm,  a significant problem has been the lack of a reusable library implementation.   This paper solves this problem through the use of a monadic interface and continuations.</p>
<p>Because Allison&#8217;s queues are not fully persistent,   they cannot be first class values.   Rather,  they are encoded in particular algorithms written in an extended continuation passing style.   In direct style, this extension corresponds to  <code>mapCont</code>,  a control operator found in <code>Control.Monad.Cont</code>, part of the Monad Template Library for Haskell.  This paper conjectures that <code>mapCont</code> cannot be expressed in terms of <code>callCC</code>,  <code>return</code>,  and <code>(&gt;&gt;=)</code>.
</p></blockquote>
<p>I intend to include a careful performance comparison before this becomes an official Monad Reader article.  Allison&#8217;s queues come out very well;  often better than two stack queues.  I have conducted a careful performance comparison in the past,  although with older versions of GHC,  and older versions of my code.   While I did take reasonably careful notes,   things have changed.    Haskell being what it is,  figuring out why is often a challenge.    In the meantime I am interested in feedback.</p>
<p>For fun,  here is something I wrote right after I first came up with the basic idea behind the paper.   It&#8217;s still the best error message I&#8217;ve gotten out of GHC.   Kudos to whomever came up with that strategically placed bit of humor!</p>
<blockquote><p>Thursday, August 25th, 2005,  5:22 am:   Back to the Future</p>
<p>I&#8217;ve been up all night, but I now have a working fragment of computer code that is entirely too cute. It&#8217;s easily the cleverest bit I&#8217;ve written in years. I managed to implement&#8230; a queue.</p>
<p>Yes, a queue.   One queue, not two.   One <i>purely functional</i> queue,  with one <i>esoteric</i> implementation! On my penultimate attempt, which was an utter failure except that it got me thinking in the right direction, I came by the most amusing error message I&#8217;ve seen to date out of GHC:</p>
<pre style="font-family:monospace;font-style:normal;">leon@deleon:~/Programs/snippets $  ghci -fglasgow-exts Queue.hs
   ___         ___ _
  / _ \ /\  /\/ __(_)
 / /_\// /_/ / /  | |      GHC Interactive, version 6.2.2, for Haskell 98.
/ /_\\/ __  / /___| |      http://www.haskell.org/ghc/
\____/\/ /_/\____/|_|      Type :? for help.

Loading package base ... linking ... done.
Compiling Queue            ( Queue.hs, interpreted )

Queue.hs:84:
    My brain just exploded.
    I can't handle pattern bindings for existentially-quantified constructors.

...

Failed, modules loaded: none.
Prelude&gt;</pre>
<p>Yeah,  mine did too.   Even I don&#8217;t fully understand my own code yet.</p></blockquote>
<p>It should be noted that I knew full well that the code I was trying wouldn&#8217;t work&#8230; but after hours of bewilderment,  not even trying to load anything into GHCi,  for amusement&#8217;s sake I simply had to try <i>something</i>.</p>
<p>Update:  (March 23)<br />
&#8211; Data.Sequence is not a real time queue:  rather,  they are amortized.<br />
&#8211; Added citation to Chris Okasaki&#8217;s Purely Functional Data Structures<br />
&#8211; Other minor changes</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/meldingmonads.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/meldingmonads.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/meldingmonads.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/meldingmonads.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/meldingmonads.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/meldingmonads.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/meldingmonads.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/meldingmonads.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/meldingmonads.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/meldingmonads.wordpress.com/5/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.melding-monads.com&blog=6077169&post=5&subd=meldingmonads&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://blog.melding-monads.com/2009/03/09/lloyd-allisons-corecursive-queues/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e62561db40e46118628b31cba87840d6?s=96&#38;d=http%3A%2F%2Fs0.wp.com%2Fi%2Fmu.gif&#38;r=PG" medium="image">
			<media:title type="html">lpsmith</media:title>
		</media:content>
	</item>
	</channel>
</rss>