This is a simplified case, and I'm completely open to another / better way to achieve this.
trait Container {
type T
def data: List[T]
}
trait Transform {
val from: Container
val to: Container
def xform: from.T => to.T
}
case class Identity(c: Container) extends Transform {
val from = c
val to = c
def xform = { t: from.T => t }
}
This gives a predictable error:
<console>:12: error: type mismatch;
found : t.type (with underlying type Identity.this.from.T)
required: Identity.this.to.T
def xform = { t: from.T => t }
The goal is basically a conversion that transforms the objects that lie at the base of the container, but in order to convince the type check (without horrible horrible castings all over the place) that the types are the same.
What is the best way to show equivalences and type relationships in this way?
As I said, it is completely open for code restructuring, and I promise in a real example that this is for a real purpose :)
source
share