Scala vs Haskell typeclasses: "catchall" instances
<p>The following Haskell type class and instance:</p>

<pre><code>class Able a where
  able :: a -&gt; Int

instance Able Int where
  able x = x
</code></pre>

<p>is commonly translated to Scala like so:</p>

<pre><code>trait Able[A] {
  def able(a: A): Int
}

implicit object AbleInt extends Able[Int] {
  def able(a: Int) = a
}
</code></pre>

<p>In Haskell I can now define a sort of catch-all instance and thereby create an instance for all Maybe types:</p>

<pre><code>instance Able a =&gt; Able (Maybe a) where
  able (Just a) = able a
  able Nothing  = 0
</code></pre>

<p>This defines an instance of <code>Able</code> for <code>Maybe Int</code>, <code>Maybe Bool</code>, etc. provided that there is an instance <code>Able</code> for <code>Int</code>, <code>Bool</code>, etc.</p>

<p>How would one do that in Scala?</p>