I have a description of a column of data of a given type. I have the following definitions:
object data {
trait OfType[T]
case object IntT extends OfType[Int]
case object DoubleT extends OfType[Double]
case object FloatT extends OfType[Float]
type DSeq[X] = scala.collection.immutable.AbstractSeq[X]
case class ColumnName[T](n:String, t: OfType[T])
case class Column[T,F[_]<:DSeq[_]](n:F[T], of: ColumnName[T])
}
I would like to have functions that operate on these columns. For example select the minimum. I have tried the following:
def min[T,F[_]<:data.DSeq[_]](col: data.Column[T,F])(using o:Ordering[T]): T = {
col match {
case data.Column(n,data.ColumnName(_,data.IntT)) => n.min(o)
case data.Column(n,data.ColumnName(_,data.DoubleT)) => ???
case data.Column(n,data.ColumnName(_,data.FloatT)) => ???
}
}
but this fails with:
error] 26 | case data.Column(n,data.ColumnName(_,data.IntT)) => n.min(o)
[error] | ^
[error] | Found: (o : Ordering[T])
[error] | Required: Ordering[B]
[error] |
[error] | where: B is a type variable which is an alias of Any
[error] | T is a type in method min which is an alias of Int
I am using dotty but I don’t think the error is specific to dotty. I have also tried several other variants with no success - same errors (see below). What am I doing wrong?
TIA
def min2[T,F[_]<:data.DSeq[_]](col: data.Column[T,F])(using Ordering[T]): T = {
col match {
case data.Column(n,data.ColumnName(_,data.IntT)) => n.min(Ordering[Int])
case data.Column(n,data.ColumnName(_,data.DoubleT)) => ???
case data.Column(n,data.ColumnName(_,data.FloatT)) => ???
}
}
def min3[T,F[_]<:data.DSeq[_]](col: data.Column[T,F])(using Ordering[T]): T = {
col match {
case c:data.Column[Int,_] => c.n.min(Ordering[Int])
case _:data.Column[Double,_] => ???
case _:data.Column[Float,_] => ???
}
}
def min4[T,F[_]<:data.DSeq[_]](col: data.Column[T,F])(using Ordering[T]): T = {
col match {
case c:data.Column[Int,_] => c.n.min(Ordering[T])
case _:data.Column[Double,_] => ???
case _:data.Column[Float,_] => ???
}
}
def min5[T,F[_]<:data.DSeq[_]](col: data.Column[T,F])(using Ordering[T]): T = {
col match {
case c:data.Column[Int,F] => c.n.min(Ordering[T])
case _:data.Column[Double,_] => ???
case _:data.Column[Float,_] => ???
}
}