I have a trait with covariant type A that declares (among others) this method:
sealed trait MaxPQ[+U] {
...
def insert[K >: U : Ordering](v: K): this.type
...
}
abstract class AbstractMaxPQ[U : Ordering] extends MaxPQ[U]
I also have this mix-in that I need to use:
trait FindMin[U] {
self: AbstractMaxPQ[U] =>
I am returning this.type because I want Node or Array based implementations of the priority queue to return current types and not MaxPQ[U].
In the array based implementation I have the following:
class ArrayMaxPQ[U : Ordering : ClassTag] ...extends AbstractMaxPQ[U] with FindMin[U]{
...
override def insert[K >: U : Ordering](v: K): ArrayMaxPQ[U] = ???
...
this is what is auto-generated by my IDE. Of course I need this method to return ArrayMaxPQ[K].
this.type doesn't take type parameters. Using higher-kinded types here also wouldn't work
def insert[K >: U : Ordering, G[_] <: MaxPQ[_]](v: K): G[K]
since G cannot be parameterized with self type in children.
I am a bit confused since this feels like a simple requirement but I cannot find language feature/syntax required to implement it.