<div dir="ltr">I think maybe you guys (Don and Andrew) are misunderstanding my proposal. The lazy/strict tradeoff is a subtle issue, and I&#39;ll be sure to re-read Okasaki&#39;s stuff with this in mind, but what I&#39;m talking about here is not a trade off. It&#39;s laziness &quot;for free&quot;. Move the strictness annotations out of the constructors and into the library functions using &#39;seq&#39;. Laziness is exposed through _separate_ functions.<br>
<br>I&#39;ll copy again my proposed versions of mapWithKey (because I made a typo the first time)<br><br>mapWithKey :: (k -&gt; a -&gt; b) -&gt; Map k a -&gt; Map k b<br>mapWithKey _ Tip = Tip<br>mapWithKey f (Bin sx kx x l r) <br>
&nbsp; = seq l&#39; $ seq r&#39; $ Bin sx kx (f kx x) l&#39; r&#39;<br>&nbsp;&nbsp;&nbsp; where l&#39; = mapWithKey f l <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; r&#39; = mapWithKey f r<br><br>mapWithKeyLazy _ Tip = Tip<br>mapWithKeyLazy f (Bin sx kx x l r) <br>&nbsp; = Bin sx kx (f kx x) (mapWithKey f l) (mapWithKey f r)<br>
<br>So mapWithKey retains all semantics, including guarantees. So would insert, and all other functions. You export a second API (maybe in a nested module) that exposes laziness. Writing another library is kind of silly since a) you want stricness 90% of the time b) it shares 90% of the code. If maintainers are willing to deal with some extra seqs here and there then we can have both libraries in one.<br>
<br>Scott<br><br><br><div class="gmail_quote">On Mon, Aug 4, 2008 at 6:18 PM, Don Stewart <span dir="ltr">&lt;<a href="mailto:dons@galois.com">dons@galois.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;">
sedillard:<br>
<div class="Ih2E3d">&gt; &nbsp; &nbsp;Hi,<br>
&gt;<br>
&gt; &nbsp; &nbsp;I found myself wanting a lazy version of Data.Map today, and by &quot;lazy&quot; I<br>
&gt; &nbsp; &nbsp;mean in the node-subtree pointers. I trust the library writers when they<br>
&gt; &nbsp; &nbsp;put strictness annotations in the fields of the tree nodes, so I&#39;m<br>
&gt; &nbsp; &nbsp;wondering what the various implications of lazy subtrees are, beyond the<br>
&gt; &nbsp; &nbsp;obvious speed hit. Does this cause space leaks beyond what lazy value<br>
&gt; &nbsp; &nbsp;pointers can already cause? Can someone point me to some reading that<br>
&gt; &nbsp; &nbsp;discusses this?<br>
&gt;<br>
&gt; &nbsp; &nbsp;Anyway, I&#39;m positing to libraries (rather than haskell-cafe) to gauge<br>
&gt; &nbsp; &nbsp;opinion about a possible rewrite of Data.Map and IntMap to remove<br>
&gt; &nbsp; &nbsp;strictness annotations (bangs) from the node constructors and move them<br>
&gt; &nbsp; &nbsp;into the functions (as seqs). &nbsp;&quot;Rewrite&quot; is maybe too strong of a word.<br>
&gt; &nbsp; &nbsp;&quot;Significant patch&quot; is more like it. It would involve only those functions<br>
&gt; &nbsp; &nbsp;that construct Bin values directly, which is not that many. Less than a<br>
&gt; &nbsp; &nbsp;days work, I think (yes that means I volunteer.) &nbsp;Semantics of everything<br>
&gt; &nbsp; &nbsp;remains unchanged, but it opens up the possibility for lazy versions of<br>
&gt; &nbsp; &nbsp;some functions.<br>
<br>
</div>How about doing it as a separate library, then we can choose either<br>
strict or lazy as the case may be?<br>
<font color="#888888"><br>
-- Don<br>
</font></blockquote></div><br></div>