title: Why can't I declare the inferred type?
body: <p>I have the following:</p>
  
  <pre><code>runcount :: (Eq a, Num b) =&gt; [a] -&gt; b
  runcount = runcountacc 0
  
  runcountacc :: (Eq a, Num b) =&gt; b -&gt; [a] -&gt; b
  runcountacc n (_:[]) = runcountacc (n+1) []
  runcountacc n (x:xs) = runcountacc (n+(if head xs==x then 0 else 1)) xs 
  runcountacc n _ = n
  </code></pre>
  
  <p>Which generates this error when I try to load it into Hugs:</p>
  
  <pre><code>:6 - Cannot justify constraints in explicitly typed binding
  *** Expression    : runcountacc
  *** Type          : (Eq a, Num b) =&gt; b -&gt; [a] -&gt; b
  *** Given context : (Eq a, Num b)
  *** Constraints   : Eq c
  </code></pre>
  
  <p>And the following error when loaded into ghci:</p>
  
  <pre><code>:6:23: Ambiguous type variable `a0' in the constraint:
    (Eq a0) arising from a use of `runcountacc'
  Probable fix: add a type signature that fixes these type variable(s)
  In the expression: runcountacc (n + 1) []
  In an equation for `runcountacc':
     runcountacc n ([x]) = runcountacc (n + 1) []
  </code></pre>
  
  <p>However when the type declaration of <code>runcountacc</code> is removed:</p>
  
  <pre><code>runcount :: (Eq a, Num b) =&gt; [a] -&gt; b
  runcount = runcountacc 0
  
  runcountacc n (_:[]) = runcountacc (n+1) []
  runcountacc n (x:xs) = runcountacc (n+(if head xs==x then 0 else 1)) xs 
  runcountacc n _ = n
  </code></pre>
  
  <p>The code loads fine and when ghci is asked what the type of <code>runcountacc</code> is, we get the following:</p>
  
  <pre><code>λ&gt; :t runcountacc 
  runcountacc :: (Num a, Eq a1) =&gt; a -&gt; [a1] -&gt; a
  </code></pre>
  
  <p>Why can't I declare the inferred type of <code>runcountacc</code>?</p>