Yes I agree, so far StableNames have been a good approximation, except for the problem I described when using monads/class constraints :-(<br><br><div class="gmail_quote">2012/6/26 Lorenzo Bolla <span dir="ltr">&lt;<a href="mailto:lbolla@gmail.com" target="_blank">lbolla@gmail.com</a>&gt;</span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">This is very tricky and it really depends on what you mean...<div>Formally, two functions are the same if they have the same domain and f(x) == g(x) for each x in the domain. But this is not always easy/feasible/efficient to implement! (See also <a href="http://en.wikipedia.org/wiki/Rice%27s_theorem" target="_blank">http://en.wikipedia.org/wiki/Rice%27s_theorem</a> and <a href="http://stackoverflow.com/questions/4844043/are-two-functions-equal" target="_blank">http://stackoverflow.com/questions/4844043/are-two-functions-equal</a>.)</div>

<div><br></div><div>Depending on your problem, you might get away with just defining a &quot;signature&quot; of your function and compare them: for example the signature could be the concat of the function name, args types, etc. But I&#39;m speculating here...</div>
<span class="HOEnZb"><font color="#888888">
<div><br></div><div>L.</div></font></span><div class="HOEnZb"><div class="h5"><div><br></div><div><br></div><div><br><div class="gmail_quote">On Tue, Jun 26, 2012 at 4:50 PM, Ismael Figueroa Palet <span dir="ltr">&lt;<a href="mailto:ifigueroap@gmail.com" target="_blank">ifigueroap@gmail.com</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>thanks again for your comments, any idea on how to implement &quot;Equivalence&quot; for functions?</div><div>
<div><br><div class="gmail_quote">2012/6/26 Lorenzo Bolla <span dir="ltr">&lt;<a href="mailto:lbolla@gmail.com" target="_blank">lbolla@gmail.com</a>&gt;</span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">In other words there is a difference between Identity and Equivalence. What you have implemented with StableName is an &quot;Identity&quot; (sometimes called &quot;reference equality&quot;), as opposed to an &quot;Equivalence&quot; (aka &quot;value equality&quot;).<div>



<br></div><div>In Python, for example:</div><div><br></div><div><div>&gt;&gt;&gt; x = {1:2}</div><div>&gt;&gt;&gt; y = {1:2}</div><div>&gt;&gt;&gt; x == y</div><div>True</div><div>&gt;&gt;&gt; x is y</div><div>False</div>


<span><font color="#888888">
<div><br></div><div>L.</div></font></span><div><div><div><br></div><br><div class="gmail_quote">On Tue, Jun 26, 2012 at 3:42 PM, Lorenzo Bolla <span dir="ltr">&lt;<a href="mailto:lbolla@gmail.com" target="_blank">lbolla@gmail.com</a>&gt;</span> wrote:<br>



<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I think about StableName like the &quot;&amp;&quot; operator in C, that returns you the memory address of a variable. It&#39;s not the same for many reasons, but by analogy, if &amp;x == &amp;y then x == y, but &amp;x != &amp;y does not imply x != y.<div>




<br></div><div>So, values that are semantically equal, may be stored in different memory locations and have different StableNames.</div><div><div><br><div>The fact that changing the order of the lines also changes the result of the computation is obviously stated in the type signature of makeStableName, which lives in the IO monad. On the other hand hashStableNAme is a pure function.</div>



<span><font color="#888888">
<div><br></div><div>L.</div></font></span><div><div><div><br></div><div><br></div><div><br><div class="gmail_quote">On Tue, Jun 26, 2012 at 3:26 PM, Ismael Figueroa Palet <span dir="ltr">&lt;<a href="mailto:ifigueroap@gmail.com" target="_blank">ifigueroap@gmail.com</a>&gt;</span> wrote:<br>




<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br><br><div class="gmail_quote"><div>2012/6/26 Lorenzo Bolla <span dir="ltr">&lt;<a href="mailto:lbolla@gmail.com" target="_blank">lbolla@gmail.com</a>&gt;</span><br>




<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
The point I was making is that StableName might be what you want. You are using it to check if two functions are the same by comparing their &quot;stablehash&quot;. But from StableName documentation:<div><br><div><div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
The reverse is not necessarily true: if two stable names are not equal, then the objects they name may still be equal. </blockquote><div><br></div></div><div>The `eq` you implemented means this, I reckon: if `eq` returns True then the 2 functions are equal, if `eq` returns False then you can&#39;t tell!</div>






<div><br></div><div>Does it make sense?</div><span><font color="#888888"><div>L.</div></font></span></div></div></blockquote><div><br></div></div><div>Yes  it does make sense, and I&#39;m wondering why the hash are equal in one case but are not equal on the other case (i.e. using let/where vs not using it) because I&#39;d like it to behave the same in both situations </div>





<div><br></div><div>Thanks again</div><div><div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div><div><div><div><br></div><div><br><div class="gmail_quote">





On Tue, Jun 26, 2012 at 1:54 PM, Ismael Figueroa Palet <span dir="ltr">&lt;<a href="mailto:ifigueroap@gmail.com" target="_blank">ifigueroap@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Thanks Lorenzo, I&#39;m cc&#39;ing the list with your response also:<div><br></div><div>As you point out, when you do some kind of &quot;let-binding&quot;, using the where clause, or explicit let as in:</div>






<div><br></div>
<div><div><div>main :: IO () </div><div>main = do</div></div><div>       let f1 = (successor :: Int -&gt; State Int Int)</div><div>       let f2 = (successor :: Int -&gt; Maybe Int)</div><div><div>       b2 &lt;- eq f2 f2</div>






<div>       b1 &lt;- eq f1 f1</div>
<div>       print (show b1 ++ &quot; &quot; ++ show b2)</div></div></div><div><br></div><div>The behavior is as expected. I guess the binding triggers some internal optimization or gives more information to the type checker; but I&#39;m still not clear why it is required to be done this way -- having to let-bind every function is kind of awkward.</div>







<div><br></div><div>I know the details of StableNames are probably implementation-dependent, but I&#39;m still wondering about how to detect / restrict this situation.</div><div><br></div><div>Thanks</div><div><div><div>






<br><br><div class="gmail_quote">
2012/6/26 Lorenzo Bolla <span dir="ltr">&lt;<a href="mailto:lbolla@gmail.com" target="_blank">lbolla@gmail.com</a>&gt;</span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">