How can I constrain the type parameters of a trait to be among a distinct set of types (eg., bound by union type)?
As a concrete example, I'd like to create a trait IntegralIndex[T] where T must Int or Long.
I tried the first answer to this question on union types :
sealed abstract class NumericIndex[T]
object NumericIndex {
implicit object IntWitness extends NumericIndex[Int]
implicit object LongWitness extends NumericIndex[Long]
}
trait IntegralIndex[T : NumericIndex]
but that doesn't work; I get traits cannot have type parameters with context bounds `: ...' nor view bounds `<% ...'
Any other suggestions? Admittedly, I didn't understand the other solutions to the question on union types, so I'd appreciate if the answer is just to use a different answer there, or even to know that it can't be done.