Непонятно, как достичь зависимых от пути типов в следующем фрагменте. Цель состоит в том, чтобы иметь возможность использовать метод «meld» для слияния двух куч. Для AFAIK требуются типы, зависящие от пути.Noob to scala зависимые от типа типы
Вот черта
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
}
Возвращаемое значение "это" по методу оплавления страдает ошибку компиляции:
Expression HeapImpl does not conform to expected type Heap#H