よりさらに後に持ち越し type Vector[T any] []T type IntVector = Vector[int] // OK ( 型エイリアス宣言は型パラメータを持っていない) type Map[K comparable, V any] map[K]V type StringMap[V any] = Map[string]V // NG (Go 1.18 時点では書けないが、将来的には書けるようになる見込み)
は比較可能な型のみを含む。map のキーに使える exp/constraints.Ordered は < 演算子で順序付け可能な型のみを含む これらで足りなかった時に初めて自分で型制約を書けばOK import "golang.org/x/exp/constraints" func Min[T constraints.Ordered](a, b T) bool { if a < b { return a } return b }
と考えてしまうので、コードリーディングのコストが上がる可能性 がある Go Team は型推論の優先度を高く設定して対応しているので、直近型 推論が効かない箇所も、じきに効くようになることが期待できる https://github.com/golang/go/issues/46477#issuecomment- 1490490920