This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Type conflict (type argument versus abstract method)

No replies
Sciss
Joined: 2008-12-17,
User offline. Last seen 28 weeks 5 days ago.

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-

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland