title: How can I combine the typeclass pattern with subtyping?
body: <p>Suppose I'm using the typeclass pattern in Scala.  Here's how I make a class C
  part of the typeclass Foo:</p>
  
  <pre><code>Welcome to Scala version 2.9.0.1 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_26).
  
  scala&gt; trait Foo[T] { def foo(t: T) }
  defined trait Foo
  
  scala&gt; def foo[T : Foo](t: T) { implicitly[Foo[T]].foo(t) }
  foo: [T](t: T)(implicit evidence$1: Foo[T])Unit
  
  scala&gt; class C
  defined class C
  
  scala&gt; foo(new C)
  &lt;console&gt;:11: error: could not find implicit value for evidence parameter of type Foo[C]
         foo(new C)
            ^
  
  scala&gt; implicit object FooC extends Foo[C] { override def foo(c: C) { println("it's a C!") } }
  defined module FooC
  
  scala&gt; foo(new C)
  it's a C!
  </code></pre>
  
  <p>So far so good.  But suppose I have a subclass D of C, and I want instances of D to be "in" the typeclass too:</p>
  
  <pre><code>scala&gt; class D extends C
  defined class D
  
  scala&gt; foo(new D)
  &lt;console&gt;:13: error: could not find implicit value for evidence parameter of type Foo[D]
         foo(new D)
            ^
  </code></pre>
  
  <p>Doh!  How do I make this work without having to explicitly provide a typeclass instance for D?</p>