<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 <- makeStableName x</div><div> py <- 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"><<a href="mailto:dav.vire%2Bhaskell@gmail.com" target="_blank">dav.vire+haskell@gmail.com</a>></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>
<<a href="mailto:echant%2Bhaskell@maretmanu.org" target="_blank">echant+haskell@maretmanu.org</a>> wrote:<br>
<br>
> In my futur program, it use a lot of binary trees with strings (words)<br>
> as leaf. There is just arround 1000 words and they will appear a lot of<br>
> times. The program will possibly consume a lot of process and memory<br>
> (it is a mathematics proover).<br>
<br>
> I began this program in C++ but haskell has a prety good speed and<br>
> memory footprint and is easier. But I don't know if it worth to do this<br>
> optimization: having a dictionary to translate string words in Int.<br>
<br>
> The answer depends on the automatic optimizations in GHC, because GHC<br>
> could compare quickely two strings if it is the same object, so it<br>
> depends if program generated by GHC have a dictionary (tree) of strings<br>
> internaly. Someone knows this ?<br>
<br>
</div>It doesn'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) => Eq [a] where<br>
[] == [] = True<br>
(x:xs) == (y:ys) = x == y && 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'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'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>