Question

Was just looking at this question: removing redundant type in Interface. Turns out not to be possible to eliminate type parameter T in C#. Is this related to higher-kinded types? Does Scala fix this?

Était-ce utile?

La solution

This has nothing to do with higher-kinded types. The question is, does IRevisionControl need to know T? If not, you can use an existential type

trait Revision[RevisionType]
trait RevisionLog

trait RevisionControl[R <: Revision[_], L <: RevisionLog]

If you need T, you either have to add it as another type parameter...

trait RevisionControl[T, R <: Revision[T], L <: RevisionLog]

...or you use a type member in Revision...

trait Revision {
  type RevisionType
}

trait RevisionControl[R <: Revision, L <: RevisionLog] {
  def foo: R#RevisionType = ???
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top