title: specifying trait constraint in scala
body: <p>I want to test a number of stackable <code>traits</code> that extend from such one as this: </p>
  
  <pre><code>trait Layer{
    def write(s:String): String
  }
  </code></pre>
  
  <p>Each one process the incoming string somehow and then passes it to the next layer, for example: </p>
  
  <pre><code>trait TimeStampLayer { 
    abstract override def write(s:String) = System.nanotime + super.write(s)
  } 
  </code></pre>
  
  <p>My idea was to write a base test class whith such a fixture: </p>
  
  <pre><code>abstract LayerTest { 
  
     type L
  
     val layer = new BaseLayer with L      // BaseLayer would be one that does nothing
  
  } 
  </code></pre>
  
  <p>where each test subclass would overwrite <code>L</code> with such an stackable <code>trait</code>.
  This of course doesn't work, since there's no constraint on <code>L</code> to specify it's a trait. Quoting the compiler, </p>
  
  <blockquote>
    <p>type L needs to be a trait to be mixed in</p>
  </blockquote>
  
  <p>I also thought of something like</p>
  
  <pre><code>abstract LayerTest[L &lt;: Layer] {
    //...
  }
  
  class TimeStampLayerTest extends LayerTest[TimeStampLayer] {}
  </code></pre>
  
  <p>but I also can't constrain <code>L</code> to be a trait, or at least don't know how to</p>
  
  <p>Is there any way to specify that a type is a trait?</p>