Мне неясно, как добиться зависимых от пути типов в следующем фрагменте. Намерение состоит в том, чтобы иметь возможность использовать метод «объединения» для объединения двух куч. Для этого AFAIK требуются типы, зависящие от пути.
Вот это черта
trait Heap {
type H // type of a heap
type A // type of an element
def ord: Ordering[Heap#A] // ordering on elements
def meld(h1: Heap#H, h2: Heap#H): Heap#H // the heap resulting from merging h1 and h2
..
}
Вот часть реализации
class HeapImpl extends Heap {
override type H = HeapImpl // this.type
override type A = Integer
..
// the heap resulting from inserting x into h
override def meld(h1: Heap#H, h2: Heap#H): Heap#H = {
while (!isEmpty(h2)) {
insert(deleteMin(h2),h1)
}
this
}
Возвращаемое значение "this" в методе объединения вызывает ошибку компиляции:
Expression HeapImpl does not conform to expected type Heap#H