title: Function equality and ordering in Erlang
body: <p>What does it mean to compare functions in Erlang with the operators <code>=:=</code>,<code>==</code>,<code>&lt;</code>,<code>&gt;</code>,<code>=&lt;</code>,<code>&gt;=</code>?</p>
  <p>I was playing around with the interpreter and got these results:</p>
  <pre><code>Eshell V5.9.2  (abort with ^G)
  1&gt; X = fun() -&gt; {} end.
  #Fun&lt;erl_eval.20.82930912&gt;
  2&gt; Y = fun() -&gt; {} end.
  #Fun&lt;erl_eval.20.82930912&gt;
  3&gt; 
  3&gt; {X == X, X =:= X}.
  {true,true}
  4&gt; {X &gt;= X, X =&lt; X}.
  {true,true}
  5&gt; {X &gt; X, X &lt; X}.
  {false,false}
  6&gt; 
  6&gt; {X == Y, X =:= Y}.
  {true,true}
  7&gt; {X &gt;= Y, X =&lt; Y}.
  {true,true}
  8&gt; {X &gt; Y, X &lt; Y}.
  {false,false}
  </code></pre>
  <p>This makes sense. It looks like it's comparing the abstract syntax tree of the two functions.</p>
  <p>But in this session <code>X</code> and <code>Y</code> are defined the same once again but are different, also now <code>X&lt;Y</code>?</p>
  <pre><code>Eshell V5.9.2  (abort with ^G)
  1&gt; X = fun() -&gt; {} end.
  #Fun&lt;erl_eval.20.82930912&gt;
  2&gt; 
  2&gt; {X == X, X =:= X}.
  {true,true}
  3&gt; {X &gt;= X, X =&lt; X}.
  {true,true}
  4&gt; {X &gt; X, X &lt; X}.
  {false,false}
  5&gt; 
  5&gt; Y = fun() -&gt; {} end.
  #Fun&lt;erl_eval.20.82930912&gt;
  6&gt; 
  6&gt; {X == Y, X =:= Y}.
  {false,false}
  7&gt; {X &gt;= Y, X =&lt; Y}.
  {false,true}
  8&gt; {X &gt; Y, X &lt; Y}.
  {false,true}
  </code></pre>
  <p>So it looks like it's not comparing the AST <strong>or</strong> any sort of unique references. Maybe it is comparing references, just some optimization is happening and <code>X</code> and <code>Y</code> get bound to the same reference? If there is some explanation for this, what happens across different VMs or different nodes?</p>