Groups
Sign in
Groups
golang-nuts
Conversations
About
Send feedback
Help
Misunderstaing the Language spec on Type parameter declarations
81 views
Skip to first unread message
Millicent Caputitl
unread,
Jun 22, 2022, 6:22:58 PM
6/22/22
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to golang-nuts
The ending statement on the Language spec on section Type parameter declarations, states
Type parameters may also be declared by the receiver specification of a method declaration associated with a generic type.
Does it mean something like this?
type I interface {
string | int
}
func Double[T I](value T) {
fmt.Println(value)
}
Ian Lance Taylor
unread,
Jun 22, 2022, 6:50:49 PM
6/22/22
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Millicent Caputitl, golang-nuts
No, it means something like
type Slice[E any] []E
func (s Slice[E]) First() E { return s[0] }
The receiver specification of the method First is Slice[E], which
declares the type parameter E.
Ian
Reply all
Reply to author
Forward
0 new messages