title: How to get around the error "Type mismatch, expected: _$1, actual: Any" in scala?
body: <p>I have a scenario similar to the following example</p>
  
  <pre><code>// Reads from somewhere and returns List of type A
  trait Reader[A]  {
    def read(): List[A]
  
  }
  
  // Transforms element of type A, performs some operation
  // and converts result to string
  trait Translator[A]  {
    def translate(a: A): String
  }
  
  
  
  object Factory {
  
    def getReader(readerName:String) = {
  
      readerName match {
       case "one" =&gt;  new Reader[String] {
          override def read() = List("sasha")
       }
       case "two" =&gt; new Reader[Int] {
          override def read() = List(3)
       }
       case _ =&gt; throw new IllegalArgumentException
     }
  
   }
  
   def getTranslator(translatorName:String) =  {
  
     translatorName match {
       case "one" =&gt; new Translator[String] {
          override def translate (a: String) = a + " " + "nice!!!"
       }
       case "two" =&gt; new Translator[Int] {
          override def translate(a: Int) = (a+2).toString
       }
       case "three" =&gt; new Translator[Int] {
          override def translate(a: Int) = (a+3).toString
       }
       case _ =&gt; throw new IllegalArgumentException
     }
   }
  
  }
  </code></pre>
  
  <p>Now when I do <code>Factory.getReader("one").read().map(a =&gt; Factory.getTranslator("one").translate(a))</code>, I get a compile time error "Type mismatch, expected: _$1, actual: Any".</p>
  
  <p>If I am not wrong, compiler is saying it can't tell if the type <code>A</code> of reader is same as type <code>A</code> of translator.</p>
  
  <p>I am unable to find online, how I can get around this problem ? Am I doing something fundamentally wrong in defining the classes the way I have ?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Reason I have separate reader and translator is that, they seem to have different jobs, and I could apply more than one translator to the output of one reader (translator 2 and 3 above can be applied to output of reader 2).</p>