Hello,
I get the error:
type mismatch;
[error] found : acc.type (with underlying type ColumnMajor.Metrics#AllColumns)
[error] required: e.AllColumns
[error] val nacc = e.append(acc, all)
[error] ^
[error] two errors found
When using the following test example:
object ColumnMajor {
class Metric[T](val value:T)
case class M1(override val value: Double) extends Metric[Double](value)
case class M2(override val value: Double) extends Metric[Double](value)
trait Metrics {
type All
type AllColumns
val calculate: All
val zero : AllColumns
def append(acc: AllColumns, e: All) : AllColumns
}
case class Binary() extends Metrics {
override type All = (M1,M2)
override type AllColumns = (List[M1], List[M2])
override val calculate : All = (M1(0),M2(1))
override val zero: AllColumns = (List[M1](), List[M2]())
override def append(acc: AllColumns, e: All): AllColumns = {
(e._1 :: acc._1, e._2 :: acc._2)
}
}
trait MetricEval {
type Z = Metrics
def collectOnly3(metrics: => Stream[Z]) = {
val zero: Z#AllColumns = metrics.head.zero
metrics.foldLeft(zero) {
(acc, e: Z) =>
val all: e.All = e.calculate
val nacc = e.append(acc, all)
nacc
}
}
}
}
How can (should) I encode the fact that e.All
in collectOnly3
is in fact Z#All
and the same for the
case of AllColumns
? What is the correct way of encoding such a usage pattern?
TIA.