title: Why can't the number literal 2 match the type Integer in the following code?
body: <pre><code>class R r where
      sum_ :: Integer -&gt; r
  instance R Integer where
      sum_ x = x
  instance (Integral a, R r) =&gt; R (a -&gt; r) where
      sum_ x = \y -&gt; sum (x + toIngeter y)
  </code></pre>
  
  <p>The code above is used to sum a sequence of numbers and it can accept variable number of arguments. It runs correctly.</p>
  
  <p>However, if I change the second instance to this:</p>
  
  <pre><code>instance (R r) =&gt; R (Integer -&gt; r) where
      sum_ x = \y -&gt; sum (x + y)
  </code></pre>
  
  <p>and enable FlexibleInstances (otherwise a compile error will be raised in ghc 7.10.2), the function cannot run for multiple parameters.</p>
  
  <p>For example, if I run</p>
  
  <pre><code>sum_ 1 2
  </code></pre>
  
  <p>an error would be raised:</p>
  
  <blockquote>
    <p>Non type-variable argument in the constraint: R (a -> t)</p>
  </blockquote>
  
  <p>But if I add an explicit type signature to parameters it runs correctly:</p>
  
  <pre><code>sum_ 1 (2::Integer)
  </code></pre>
  
  <p>Why couldn't 2 match the type Integer?</p>