title: Erlang function overloads
body: <p>I've just begun fiddling with Erlang.
  I've seen a lot of examples where pattern matching is used on function declarations, like so:</p>
  
  <pre><code>factorCount (N) -&gt;
     Sqrt = math:sqrt (N),
     ISqrt = trunc(Sqrt),
     if ISqrt == Sqrt -&gt; factorCount (N, ISqrt, 1, -1);
        true          -&gt; factorCount (N, ISqrt, 1, 0)
     end.
  
  factorCount (_N, ISqrt, Candidate, Count) when Candidate &gt; ISqrt -&gt; Count;
  factorCount ( N, ISqrt, Candidate, Count) -&gt;
      case N rem Candidate of
          0 -&gt; factorCount (N, ISqrt, Candidate + 1, Count + 2);
          _ -&gt; factorCount (N, ISqrt, Candidate + 1, Count)
      end.
  </code></pre>
  
  <p>Why is it done this way?.
  e.g. </p>
  
  <pre><code>factorCount (_N, ISqrt, Candidate, Count) when Candidate &gt; ISqrt -&gt; Count;
  factorCount ( N, ISqrt, Candidate, Count) -&gt;
  </code></pre>
  
  <p>Why is that not just one function with an internal condition inside of it?</p>