You can do this, but this requires a little extra hardware:
trait Bar { type MyType } object Bar { def compareTypes[L <: Bar, R <: Bar](left: L, right: R)( implicit ev: L#MyType =:= R#MyType = null ) = ev != null }
Now, if we have the following:
val intBar1 = new Bar { type MyType = Int } val intBar2 = new Bar { type MyType = Int } val strBar1 = new Bar { type MyType = String }
It works as expected:
scala> Bar.compareTypes(intBar1, strBar1) res0: Boolean = false scala> Bar.compareTypes(intBar1, intBar2) res1: Boolean = true
The trick is to ask for implicit evidence that L#MyType and R#MyType same, and provide a default value ( null ) if this is not the case. Then you can simply check if you get the default value or not.
source share