title: Scala type error with Try[Int]
body: <p>I have a problem with types that I don't understand. In the code below I have two methods <code>half1</code> and <code>half2</code> which are exactly the same except <code>half1</code>'s return type is specified explicitly. Yet when I use the two methods in a foldLeft <code>half</code> causes a compiler error. Here is the code. The line that sets <code>val c</code> has the problem.</p>
  
  <pre><code>package org.bodhi.reactive.`try`
  
  import scala.util.{Try, Success, Failure}
  
  object Hello {
     def main(args: Array[String]): Unit = {
  
      val list = List(1,2,3)
  
      Try(1024).flatMap(half1)
      Try(1024).flatMap(half2)
  
      half1(1024).flatMap(half1)
      half2(1024).flatMap(half2)
  
      val a = list.foldLeft(Try(1024))((accum, n) =&gt; accum.flatMap(half1))
      val b = list.foldLeft(half1(1024))((accum, n) =&gt; accum.flatMap(half1))
      val c = list.foldLeft(half2(1024))((accum, n) =&gt; accum.flatMap(half2)) // Compiler error
  
    }
  
    def half1(n: Int): Try[Int] =  
      if (n % 2 == 0) Success(n / 2)
      else Failure(new Exception(s"WRONG $n"))
  
    def half2(n: Int) =
      if (n % 2 == 0) Success(n / 2)
      else Failure(new Exception(s"WRONG $n"))
  }
  </code></pre>
  
  <p>The error I get is:</p>
  
  <pre><code>[error] /home/chris/projects/reactive/example/src/main/scala/org/bodhi/reactive/try/Hello.scala:18: type mismatch;
  [error]  found   : scala.util.Try[Int]
  [error]  required: Product with Serializable with scala.util.Try[Int]
  [error]     val c = list.foldLeft(half2(1024))((accum, n) =&gt; accum.flatMap(half2))
  </code></pre>
  
  <p>My question is: why does <code>half1</code> comile in foldLeft, but <code>half2</code> does not?
  I am using scala 2.11.5</p>