title: Scala type checking compilation error
body: <p>I have the following functions</p>
  
  <pre><code>  def map[A,B](l: List[A])(f: A =&gt; B): List[B]
  
    def concat[A](l: List[List[A]]): List[A]
  </code></pre>
  
  <p>I wanted to implement this one </p>
  
  <pre><code>  def flatMap[A,B](l: List[A])(f: A =&gt; List[B]): List[B]
  </code></pre>
  
  <p>Now, I know that a correct solution is (so this is not the question)</p>
  
  <pre><code>  def flatMap[A,B](l: List[A])(f: A =&gt; List[B]): List[B] = 
      concat(map(l)(f))
  </code></pre>
  
  <p>But when I was trying to resolve it, I first tried with (I forgot to concat)</p>
  
  <pre><code>  def flatMap[A,B](l: List[A])(f: A =&gt; List[B]): List[B] = 
      map(l)(f)
  
  // compilation output
  [error]  found   : A =&gt; fpinscala.datastructures.List[B]
  [error]  required: A =&gt; B
  [error]     map(l)(f)
  </code></pre>
  
  <p>I cannot understand that error, because looks like the evaluation of the <code>map(l)(f)</code> is wrong, but it is not, it is the returned value of the flatMap function what is wrong.</p>
  
  <p>In fact, if a decompose the same implementation in two lines of code, we can see that the Scala compiler complains about another different error - actually is the error that I expected also in the previous code.</p>
  
  <pre><code>  def flatMap[A,B](l: List[A])(f: A =&gt; List[B]): List[B] = {
      var result = map(l)(f)
      result
    }
  
  // compilation output
  [error]  found   : fpinscala.datastructures.List[fpinscala.datastructures.List[B]]
  [error]  required: fpinscala.datastructures.List[B]
  [error]     result
  </code></pre>
  
  <p>Could anyone explain me why the compilation of the first try of code is given a different kind of error that the second one?</p>