Hello all,

Could type parameters be omitted when they could be inferred in struct 
literals? 

Here's a scenario that doesn't work today 
(https://go2goplay.golang.org/p/Jt5OGfLePuu)
package main

import (
"fmt"
)

type BinaryTree(type T) struct {
Value       T
Left, Right *BinaryTree(T)
}

func main() {
n := int(42)
tree := BinaryTree{
Value: n,
Left:  {Value: n - 1},
Right: {Value: n + 1},
}

fmt.Println(tree)
}

Instead we must be explicit at every struct literal instantiation which 
quickly becomes quite cluttered 
(https://go2goplay.golang.org/p/vi6GM4AxyV_r):

package main

import (
"fmt"
)

type BinaryTree(type T) struct {
Value       T
Left, Right *BinaryTree(T)
}

func main() {
n := int(42)
tree := BinaryTree(int) {
Value: n,
Left:  &BinaryTree(int){Value: n - 1},
Right: &BinaryTree(int){Value: n + 1},
}

fmt.Println(tree)
}





-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/5609b074-75b4-49fb-b48e-2186c19d9801o%40googlegroups.com.

Reply via email to