Lyricdev
GitHub

LYR-MIG0211

a generic interface named by an associated type

hint · spec 14-cli

A note of lyric fix --from-4: Indexable<T> is IndexSet<int> with type Output = T, and Iterable<T> or Indexable<T> as the type of a value has no counterpart in Lyric 5.

Explanation

Lyric 5's Iterator, Iterable, Index and IndexSet name their element by an associated type. The migration writes Iterator<T> as Iterator<Item = T>, a conformance to Iterator<T> as Iterator with type Item = T;, and one to Iterable<T> as Iterable with type Iter = Iterator<Item = T>;.

A conformance to Indexable<T> becomes IndexSet<int> with type Output = T;, and the migration adds index and setIndex, which x[i] and x[i] = v call, forwarding to the get and set the type had. Fold them together where nothing else calls get and set.

Iterable<T> or Indexable<T> as the type of a parameter or a field is left as written: take an Iterator<Item = T>, the concrete type, or a type parameter with the interface as its bound.

Example

proposal[LYR-MIG0211] main.lyr:16:13: 'Indexable<int>' as a type has no counterpart: Lyric 5's 'IndexSet' names its element by an associated type — take the concrete type, or a type parameter with '[IndexSet<int>]'