3 ms·
One concern I have about the shape of the generics proposal as it stands is that it makes it hard to use arrays of types inside of generic data structures. Bloc
by vvern 7y ago
One concern I have about the shape of the generics proposal as it stands is that it makes it hard to use arrays of types inside of generic data structures. Block-based data structures are a staple of efficient programming. Having a generic B-Tree-backed sorted map would be wonderful. Also wonderful would be a library implementing a dequeue backed by a linked list of ring-buffers.
Maybe I'm missing something in the proposal but it seems like it's awkward to build these in the current proposal with contracts as type lists and methods. One option is to implement a `slice()` method on your array types and then interact with them as such.
```
interface Array(A, T) {
A slice() []T
}
type Dequeue(type A, T Array) struct {
...
}
```
Then you'd do something like:
```
type intArray8 [8]int
func (ia intArray8) slice() []int { return ia[:] }
func newIntDequeue() *Dequeue(intArray, int) {
...
}
```
But there's something that feels dirty about that.