&quot; In fact, the correct answer is that pEqualsP should produce an error and qEqualsQ should never terminate&quot;<br><br><div>¿¿???<br><div>should? or you want to say &quot;actually do that so the optimization does is not done&quot;?</div>
<div><br></div><div>The correct amswer is not the sould you mention, but True (IMHO). So the optimization can be done anyway.</div><div><br><div class="gmail_quote">2009/12/3 Neil Brown <span dir="ltr">&lt;<a href="mailto:nccb2@kent.ac.uk">nccb2@kent.ac.uk</a>&gt;</span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="im">Emmanuel CHANTREAU wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Le Thu, 3 Dec 2009 13:20:31 +0100,<br>
David Virebayre &lt;<a href="mailto:dav.vire%2Bhaskell@gmail.com" target="_blank">dav.vire+haskell@gmail.com</a>&gt; a écrit :<br>
<br>
  <br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
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>
</blockquote>
<br>
Hello<br>
<br>
Thank you David and Bulat for your answers.<br>
<br>
I don&#39;t see the proof you see. Because GHC could store two sames<br>
objects juste once and by the definition of == on lists it could deduce<br>
that &quot;forall x; List x =&gt; x==x&quot;. GHC have all informations to do this<br>
optimization job, because haskell functions definitions are mathematics<br>
definitions.<br>
  <br>
</blockquote></div>
Besides any other reasons, Haskell has the error function, and infinite lists.  Consider:<br>
<br>
p :: String<br>
p = error &quot;Haha!&quot;<br>
<br>
q :: String<br>
q = repeat &#39;a&#39;<br>
<br>
pEqualsP :: Bool<br>
pEqualsP = p == p<br>
<br>
qEqualsQ :: Bool<br>
qEqualsQ = q == q<br>
<br>
By your rule, pEqualsP and qEqualsQ should be True.  In fact, the correct answer is that pEqualsP should produce an error and qEqualsQ should never terminate.  Since Strings can contain such errors and infinite lists, you can&#39;t know for certain that an object equals itself without checking its entire length, which is what the original definition for equals did anyway.  There may be strict data structures for which your optimisation might be applicable, though.<br>
<font color="#888888">
<br>
Neil.</font><div><div></div><div class="h5"><br>
_______________________________________________<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><br></div></div>