Closed
Description
https://go.googlesource.com/proposal/+/master/design/go2draft-contracts.md
Can we maybe just reorder the generic parentheses like array brackets order please?
So everything is exactly the same as the current contract proposal just reordered a bit.
package graph
contract (Node, Edge)G {
Node Edges() []Edge
Edge Nodes() (from, to Node)
}
type (type Node, Edge G) Graph struct { ... }
func (type Node, Edge G) New(nodes []Node) (Node, Edge)*Graph { ... }
func (g (Node, Edge)*Graph) ShortestPath(from, to Node) []Edge { ... }
// Instead of this
contract G(Node, Edge) {
Node Edges() []Edge
Edge Nodes() (from, to Node)
}
type Graph(type Node, Edge G) struct { ... }
func New(type Node, Edge G)(nodes []Node) *Graph(Node, Edge) { ... }
func (g *Graph(Node, Edge)) ShortestPath(from, to Node) []Edge { ... }
Basically following the same order as array's get declared [5]int
Related to: #36177 but yet another suggestion in case it wasn't suggested before
EDIT: Iteration of this proposal (see comments) to something like this to separate generics completely from regular go code
package graph
contract (Node, Edge)G {
Node Edges() []Edge
Edge Nodes() (from, to Node)
}
type (type Node, Edge G) ( Graph )
func (type Node, Edge G) ( New )
const _ = (Node, Edge) Graph
type Graph struct { ... }
func New(nodes []Node) *Graph { ... }
func (g *Graph) ShortestPath(from, to Node) []Edge { ... }
General generics issue: #15292 (see comment below)