- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Type conflict (type argument versus abstract method)
Mon, 2010-12-13, 23:09
hello,
i am trying to solve a type problem, which roughly goes as follows... i have an enumeration of Rates:
sealed trait Rate
case object AudioRate extends Rate
case object ControlRate extends Rate
and a something associated with a Rate:
trait GE {
def rate: Rate
}
trait AudioRated { def rate = AudioRate }
and then specific composed objects:
case class DiskOut( buf: GE, multi: GE ) extends GE with AudioRated
now i would like to constrain the compile-time requirements for arguments such as the "multi" in the above case class. i was thinking of something like this:
trait GE[ R <: Rate ] {
def rate: R
}
case class DiskOut( buf: GE[ _ <: Rate ], multi: GE[ AudioRate.type ])
extends GE[ AudioRate.type ] with AudioRated
but this results in:
:32: error: overriding method rate in trait GE of type => AudioRate.type;
method rate in trait AudioRated of type => object AudioRate has incompatible type
case class DiskOut( buf: GE[ _ <: Rate ], multi: GE[ AudioRate.type ]) extends GE[ AudioRate.type ] with AudioRated
^
i would like to keep the rate method to be able to match an unknown object against its Rate.
any ways to solve this?
thanks, -sciss-