Hmmmkay.  I&#39;m not entirely convinced, &#39;cause I&#39;ve seen genuine (and benchmarked) speedups in applying some of these ideas to my TrieMap library, but I don&#39;t have any examples handy.<br><br clear="all">Louis Wasserman<br>

<a href="mailto:wasserman.louis@gmail.com">wasserman.louis@gmail.com</a><br><a href="http://profiles.google.com/wasserman.louis">http://profiles.google.com/wasserman.louis</a><br>
<br><br><div class="gmail_quote">On Tue, Feb 22, 2011 at 9:10 PM, Johan Tibell <span dir="ltr">&lt;<a href="mailto:johan.tibell@gmail.com">johan.tibell@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

On Tue, Feb 22, 2011 at 6:53 PM, Louis Wasserman<br>
<div class="im">&lt;<a href="mailto:wasserman.louis@gmail.com">wasserman.louis@gmail.com</a>&gt; wrote:<br>
</div><div class="im">&gt; Here&#39;s the approach I was attempting: a while back there was a proposal to<br>
&gt; modify Data.Map to support a sort of zipper, including the following API:<br>
&gt;<br>
&gt; data Location k a -- represents a map with a &quot;hole&quot; at a particular key<br>
&gt;<br>
&gt; search :: k -&gt; Map k a -&gt; (Maybe a, Location k a)<br>
&gt;<br>
&gt; key :: Location k a -&gt; k<br>
&gt;<br>
&gt; assign :: a -&gt; Location k a -&gt; Map k a<br>
&gt; clear :: Location k a -&gt; Map k a<br>
&gt;<br>
&gt; and from here you might define<br>
&gt;<br>
&gt; insert :: k -&gt; a -&gt; Map k a -&gt; Map k a<br>
&gt; insert k a m = case search k m of<br>
&gt;    (_, loc) -&gt; assign a loc<br>
&gt;<br>
&gt; The surprising thing was that this approach *increased* the speed of the Map<br>
&gt; implementation by something like 7%.<br>
<br>
</div>I&#39;m pretty sure it was a decrease overall. The function under<br>
discussion was something like insertWith.<br>
<br>
The direct implementation of insertWith was the fastest. The zipper<br>
approach was 7% faster than using a naive composition of lookup and<br>
insert to implement insertWith. The slowdown was most likely caused by<br>
the extra O(log n) allocations required to create the zipper (in<br>
essence that means reify the call stack of lookup).<br>
<font color="#888888"><br>
Johan<br>
</font></blockquote></div><br>