私は同じように見えるデータストア型クラスの束を持っています。依存するメソッドの型と型のクラス
trait FooStore[C] {
def create(f: FooId => Foo)(c: C): Foo
// update and find methods
}
私は物事を単純化したいと
sealed trait AR {
type Id
type Type
}
sealed trait FooAR extends AR {
type Id = FooId
type Type = Foo
}
trait DataStore[C] {
def create(ar: AR)(f: ar.Id => ar.Type)(c: C): ar.Type
}
に近い何かを得るために依存メソッドの型を使用することを望んが、私は試してみて、そのインスタンスを作成するときに
case class InMemory(foos: List[Foo])
object InMemory {
lazy val InMemoryDataStore: DataStore[InMemory] = new DataStore[InMemory] {
def create(ar: AR)(f: ar.Id => ar.Type)(c: InMemory): ar.Type = sys.error("not implemented")
}
}
を次のようにして
次のコンパイルエラーが発生する
object creation impossible, since method create in trait DataStore of type (ar: AR)(f: ar.Id => ar.Type)(c: InMemory)ar.Type is not defined
lazy val InMemoryDataStore: DataStore[InMemory] = new DataStore[InMemory] {
^
one error found
このメソッドはDataStore
インスタンスでかなり明確に定義されているため、わかりません。エラーは何を意味し、これは可能ですか?そうでない場合は、同じことを達成する別の方法がありますか?
あなたは '-Ydependent-method-types'でコンパイルしていますか? – mergeconflict
@mergeconflict:はい、依存するメソッドタイプでコンパイル – purefn