<br><br><div class="gmail_quote"><div>Use makeStableName from System.Mem.StableName</div><div><br></div><div>StableName`s are just for checking pointer equality. Instead of checking for equality of the strings, check for pointer equality of their stableNames</div>

<div><br></div><div>a dirty way:</div><div>pointerEq x y= unsafePerformIO $ do</div><div>       px &lt;- makeStableName x</div><div>       py &lt;- makeStableName  y</div><div>       return x == y</div><div><br></div><div>

<span style="font-family:arial, sans-serif;font-size:13px;border-collapse:collapse">pEq  x  y |  pointerEq x y == True = True </span></div><div><span style="font-family:arial, sans-serif;font-size:13px;border-collapse:collapse">              | otherwise = x == y</span></div>

<div><span style="font-family:arial, sans-serif;font-size:13px;border-collapse:collapse">  </span></div><div><br><br><div class="gmail_quote">2009/12/3 David Virebayre <span dir="ltr">&lt;<a href="mailto:dav.vire%2Bhaskell@gmail.com" target="_blank">dav.vire+haskell@gmail.com</a>&gt;</span><div>
<div></div><div class="h5"><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>On Thu, Dec 3, 2009 at 1:03 PM, Emmanuel CHANTREAU<br>
&lt;<a href="mailto:echant%2Bhaskell@maretmanu.org" target="_blank">echant+haskell@maretmanu.org</a>&gt; wrote:<br>
<br>
&gt; In my futur program, it use a lot of binary trees with strings (words)<br>
&gt; as leaf. There is just arround 1000 words and they will appear a lot of<br>
&gt; times. The program will possibly consume a lot of process and memory<br>
&gt; (it is a mathematics proover).<br>
<br>
&gt; I began this program in C++ but haskell has a prety good speed and<br>
&gt; memory footprint and is easier. But I don&#39;t know if it worth to do this<br>
&gt; optimization: having a dictionary to translate string words in Int.<br>
<br>
&gt; The answer depends on the automatic optimizations in GHC, because GHC<br>
&gt; could compare quickely two strings if it is the same object, so it<br>
&gt; depends if program generated by GHC have a dictionary (tree) of strings<br>
&gt; internaly. Someone knows this ?<br>
<br>
</div>It doesn&#39;t work this way : Strings are just lists of Chars. Comparison<br>
is made recursively, Char by Char. You can have a look at the source<br>
to make sure :<br>
<br>
instance (Eq a) =&gt; Eq [a] where<br>
    []     == []     = True<br>
    (x:xs) == (y:ys) = x == y &amp;&amp; xs == ys<br>
    _xs    == _ys    = False<br>
<br>
So you will have to code your own optimisation.<br>
<br>
David.<br>
<br>
P.S. In French if you didn&#39;t understand:<br>
<br>
Ca ne marche pas comme ça.<br>
Les chaines de caractères ne sont que des listes de caractères.<br>
La comparaison sur les listes est faite récursivement, caractère par<br>
caractère, il suffit pour s&#39;en assurer de regarder au source :<br>
Donc il vaut mieux que tu implémente ton propre dictionnaire.<br>
<div><div></div><div>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org" target="_blank">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
</div></div></blockquote></div></div></div><br></div>
</div><br>