On Thu, Oct 27, 2011 at 10:03 AM, Edward Z. Yang <span dir="ltr"><<a href="mailto:ezyang@mit.edu">ezyang@mit.edu</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
I'd like to remark that the situation with keys is not /quite/ comparable.<br>
Even if we don't need to look at the key for inserting into an empty map,<br>
it will get forced anyway because IntMaps are spine-strict (in particular, they<br>
are strict in their keys.)</blockquote><div class="gmail_quote"><br></div><div class="gmail_quote">I'm not quite sure if I follow. Here's Data.IntMap.insert:</div><br> insert :: Key -> a -> IntMap a -> IntMap a<br>
insert k x t = k `seq`<br> case t of<br> Bin p m l r<br> | nomatch k p m -> join k (Tip k x) p t<br> | zero k m -> Bin p m (insert k x l) r<br> | otherwise -> Bin p m l (insert k x r)<br>
Tip ky _<br> | k==ky -> Tip k x<br> | otherwise -> join k (Tip k x) ky t<br> Nil -> Tip k x</div><div class="gmail_quote"><br></div><div class="gmail_quote">Without the explicit `seq`</div>
<div class="gmail_quote"><br></div><div class="gmail_quote"> insert undefined 1 Nil</div><div class="gmail_quote"><br></div><div class="gmail_quote">terminates but with the `seq` it's _|_.</div><div class="gmail_quote">
<br></div><div class="gmail_quote">Are you saying it will eventually get force if someone e.g. does a lookup after the insert?</div><div class="gmail_quote"><br><div>-- Johan</div><div> </div></div>