scala 3.3.0-RC3
sealed trait BoundTuple[N]:
def toTuple: Tuple = this match
case self: BoundTuple.Cons[N, h,t] => self.head *: self.tail.toTuple
case self: BoundTuple.Empty => EmptyTuple
object BoundTuple:
case class Cons[N, H <: N,T <: BoundTuple[N]](head: H, tail: T) extends BoundTuple[N]
case object Empty extends BoundTuple[Nothing]
type Empty = Empty.type
type Union[N, Ns <: BoundTuple[N]] <: N = Ns match
case Cons[N,h,t] => h | Union[N, t]
case Empty => Nothing
Compilation fails for the second-to-last line:
Found: h | Playground.BoundTuple.Union[N, t]
Required: N
where: h is a type in type Union with bounds <: Playground.BoundTuple.Cons[?, ?, ?]#N²
t is a type in type Union with bounds <: Playground.BoundTuple[?]
I would so love this to work; I’m eyeing this problem for over half a year now!
Any insights would be much appreciated!