title: Attempting to model F-bounded polymorphism as a type member in Scala
body: <p>I wanted to try writing a type whose methods can be homogeneous and return values of the same type:</p>
  
  <pre><code>object SimpleTest {
    trait Foo extends Product with Serializable {
      type Self &lt;: Foo
      def bar: Self
    }
  
    case class X() extends Foo {
      type Self = X
      def bar = this
    }
  
    case class Y() extends Foo {
      type Self = Y
      def bar = this
    }
  
  
    trait TC[A]
  
    implicit val tc: TC[Foo] = new TC[Foo] { }
  
    def tester[A: TC](x: Seq[A]) = "foo"
  
    // tester(Seq(X(), Y()))
  }
  </code></pre>
  
  <p>Unfortunately, the commented-out line calling <code>tester</code> fails with the following error (Scala 2.10):</p>
  
  <pre><code>Error: could not find implicit value for evidence parameter of type
  SimpleTest.TC[SimpleTest.Foo{type Self &gt;: SimpleTest.Y with SimpleTest.X &lt;: SimpleTest.Foo}]
  tester(Seq(X(), Y()))
        ^
  </code></pre>
  
  <p>Basically, I'm confused as to why <code>X</code> and <code>Y</code> don't unify to <code>Foo</code>, which seems like a clear LUB for the two of them. Clearly the type member is complicating matters but its bounds appear to be respected.</p>
  
  <p>At the higher level, I'm looking for a lightweight way to get the equivalent of F-bounded polymorphism without the overhead of pervasive type parameters. This mostly seems to work, but I need to add annotations that force <code>X</code> and <code>Y</code> to unify to <code>Foo</code>. </p>