title: overridable default type parameter in Scala
body: <p>I am trying to expose a class parametrized with a type alias:</p>
  
  <pre><code>trait Tr[T] {
    var x: T = _
  }
  
  abstract class Foo {
    type MyParameter
  
    class SomeClass extends SomeOtherClass with Tr[MyParameter]
  }
  
  class Bar extends Foo {
    override type MyParameter = Int
  
    val myObj = new SomeClass
    myObj.x = 6
  }
  
  class Qux extends Foo {
    override type MyParameter = String
  
    val myObj = new SomeClass
    myObj.x = "hello" 
  }
  </code></pre>
  
  <p>This works fine.</p>
  
  <p>Now, what I would like to do is to specify a default value for the <code>MyParameter</code> type. Like this:</p>
  
  <pre><code>abstract class Foo {
    type MyParameter = String
    // ...
  }
  
  // ...
  
  class Qux extends Foo {
    val myObj = new SomeClass
    myObj.x = "hello"
  }
  </code></pre>
  
  <p>If I do this, however, class <code>Bar</code> will fail with a type error -- apparently, at that point, <code>SomeClass</code> is already fixed to <code>String</code>.</p>
  
  <p>What can I do to fix this? Alternately, what other approach can I take to have <code>SomeClass</code> parametrized by a type that has a default, but can be overriden in subclasses of <code>Foo</code>?</p>
  
  <p>Note that <code>SomeClass</code> will be more complex than shown, so I don't want the users to have to override the definition of <code>SomeClass</code>. Also, all uses of <code>X.SomeClass</code> should use the same <code>Tr[T]</code>, so I don't want to make <code>SomeClass</code> itself parametrizable.</p>