4 ms·
For what it is worth, the equivalent Scala code is trait Pong[T] {} class Ping[T] extends Pong[Pong[X forSome { type X >: Ping[Ping[T]]}]] { def Ping(
by trurl 15y ago
For what it is worth, the equivalent Scala code is
trait Pong[T] {}
class Ping[T] extends Pong[Pong[X forSome { type X >: Ping[Ping[T]]}]] {
def Ping() {
val Ping : Pong[X forSome { type X >: Ping[Long]}] = new Ping[Long]();
}
}
which produces the errors
Test.scala:3: error: illegal cyclic reference involving class Ping
class Ping[T] extends Pong[Pong[X forSome { type X >: Ping[Ping[T]]}]] {
^
Test.scala:5: error: type mismatch;
found : Ping[Long]
required: Pong[X forSome { type X >: Ping[Long] }]
Note: Long <: X forSome { type X >: Ping[Long] }, but trait Pong is invariant in type T.
You may wish to define T as +T instead. (SLS 4.5)
val Ping : Pong[X forSome { type X >: Ping[Long]}] = new Ping[Long]();
- trurl 15y agoHowever, if you set the symbol locking depth larger (-Yrecursion n) you'll also get a stack overflow as well. So it isn't necessarily that Scala has an algorithmically better approach to subtyping. The symbol locking algorithm is more of a catchall...