Generally, you are looking for a `*ast.GenDecl` and its doc, which contains
a `ast.TypeSpec`, when it is written as `type Name Type{ ... }`. However,
though nearly never happened, people can write it as `type ( Name
Type{} )`, just like a `var` statement would. In that case, you are
lookin
Using your code as example:
> func (tl *TextList) Add(type T Stringer) (item T ) {
> tl.Data=append(tl.Data,item.String())
> }
Now if we have:
package pkg //probably written by a user you don't know that uses your code
type A struct{}
func (A) String() string { return "" }
type IA interface
Personally I am happy with the current way of expressing constraints, i.e.,
interface-like + type lists, but I do think constraints and interfaces, are
two different concepts, and forcing them into a same box does not mitigate
the extra cognitive load needed to understand generics (which, as in
> And
> * should "embeddable" be one kind of constraints?
Would you elaborate what do you mean by "embeddable"?
As for the other 3, I agree it would be good to have them as constraints.
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsub
Like this:
https://go2goplay.golang.org/p/Veu_6glrHbn
It is tricky that you need to write `(_ Foo(T))` as the returning value
declaration. Otherwise, the current parser consider it as calling the
function with argument T and returns a value of type Foo, or in case of
`(Foo(T))`, it is considere
> that quite hard to read especially at lines 7-12 '__')
It might just be me, but I don't feel anything special... Go does not have
any other syntax (e.g., macros) that let you use parentheses in type
definition unless followed immediately by a `func`, and those parentheses
can not be nested.
I don't know how many of us are here, but I for one, really feels
comfortable and familiar with use of parentheses.
I think anyone that is familiar with closures and functional programming
would see it fitting, as if the generic function is a function that takes
some type parameters and returns