3

次のような名前衝突の状況で型パラメーター/メンバーのいずれかを変更する必要がないように、エイリアシングを使用できますか?

trait Bar {
  type A
}

trait Foo {
  def get[A]: Option[Bar { type A = A }]  // "illegal cyclic reference"
}

私は書くことができることを知っています

trait Foo {
  def get[A1]: Option[Bar { type A = A1 }]
}

しかし、私は型名を変更しないことを本当に望んでいます。

4

1 に答える 1

3

たとえば、次のようなことができます。

trait Bar {
  type A
}

trait Foo {
  type M[X] = Bar { type A = X }
  def get[A]: Option[M[A]]
}

またはインライン:

def get[A]: Option[({ type X[Y] = Bar { type A = Y }})#X[A]] = ???

または、必要に応じて:

def get[A]: Option[({ type A1 = A; type X = Bar { type A = A1 }})#X] = ???
于 2013-05-04T15:31:51.080 に答える