You should seq or use a bangpattern on the arguments before taking the stable names to ensure that the result is reproducible if the input thunks may later be forced.<br><br>&gt; let y = 1 + 1; x = id y in (ptrEqual x y, x `seq` y `seq` ptrEqual x y)<br>
(False,True)<br><br>a === b = a `seq` b `seq` unsafePerformIO $ (==) &lt;$&gt; makeStableName a &lt;*&gt; makeStableName b<br>
<br>&gt; let y = 1 + 1; x = id y in (x === y, x `seq` y `seq` x === y)<br>
(True,True)<br><br>This may be less of a problem if your tree has bang patterns, but even there it it sometimes easy to trip up and make a mistake with the unforced root of a tree.<br><br>-Edward Kmett<br><br><div class="gmail_quote">
On Wed, Mar 3, 2010 at 1:08 PM, Jonathan Cast <span dir="ltr">&lt;<a href="mailto:jonathanccast@fastmail.fm">jonathanccast@fastmail.fm</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;">
<div class="im">On Wed, 2010-03-03 at 18:58 +0100, Axel Simon wrote:<br>
&gt; On 03.03.2010, at 17:30, Milan Straka wrote:<br>
&gt;<br>
&gt; &gt; Any easy way of comparing pointers? I mean, if I have something like<br>
&gt; &gt; Tree a = N | B (Tree a) a (Tree a)<br>
&gt; &gt; and have (l::Tree a) and (r::Tree a), can I ask about the &quot;physical<br>
&gt; &gt; equality&quot;?<br>
&gt;<br>
&gt; You can! Despite the names appearing in the following code, the<br>
&gt; following is safe:<br>
&gt;<br>
&gt; -- | Equality on pointers.<br>
&gt; ptrEqual :: a -&gt; a -&gt; Bool<br>
&gt; ptrEqual x y = unsafePerformIO $ do<br>
&gt;    nx &lt;- makeStableName x<br>
&gt;    ny &lt;- makeStableName y<br>
&gt;    return (nx==ny)<br>
<br>
</div>Safe but not pure?<br>
<br>
jcc<br>
<div><div></div><div class="h5"><br>
<br>
_______________________________________________<br>
Libraries mailing list<br>
<a href="mailto:Libraries@haskell.org">Libraries@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/libraries" target="_blank">http://www.haskell.org/mailman/listinfo/libraries</a><br>
</div></div></blockquote></div><br>