title: function could not match type
body: <p>I have function as below:</p>
  
  <pre><code>    foo :: Int -&gt; a -&gt; [a]
      foo n v = bar n
        where
          bar :: Int -&gt; [a]
          bar n = take n $ repeat v
  </code></pre>
  
  <p>using ghci report this error:</p>
  
  <pre><code>    Couldn't match type `a' with `a1'
            `a' is a rigid type variable bound by
                the type signature for foo :: Int -&gt; a -&gt; [a] at hs99.hs:872:1
            `a1' is a rigid type variable bound by
                the type signature for bar :: Int -&gt; [a1] at hs99.hs:875:9
      Expected type: [a1]
          Actual type: [a]
      In the expression: take n $ repeat v
      In an equation for `bar': bar n = take n $ repeat v
  </code></pre>
  
  <p>If removing the type declaration of bar, code can be compiled without error. So what's the proper type declaration of bar here? And why error happens, because type declaration of bar is more generic than definition of bar (which is bound to some type in foo)?</p>
  
  <p>Thanks for any help!</p>