On Wed, Jul 22, 2020 at 9:36 PM burak serdar <[email protected]> wrote:
>
> This is a suggestion about the declaration of a generic type. There is
> something unnatural in the syntax:
>
> type SomeIntf(type T) interface {
> ...
> }
>
> type SomeStruct(type T) struct {
> ...
> }
>
> func SomeFunc(type T)(...) {...}
>
>
> In all of the above, the names SomeIntf, SomeStruct, and SomeFunc are
> being defined as generic types. However, all the regular types are
> defined using the pattern:
>
> "type" typeName typeDefinition
>
> So why not:
>
> type SomeIntf interface(T) {
> ...
> }
>
> type SomeStruct struct(T) {
> ...
> }
>
> func(T) SomeFunc(...) {...}
You are only looking at the declarations, not the uses. I think it is
a very nice feature that we can write
type SomeStruct(type T) Struct { ... {
var S SomeStruct(int)
The declaration and the use are parallel. It is obvious from the
placement of the type parameter how the type argument should be
written.
Ian
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/golang-nuts/CAOyqgcXK2Q%3DNL4OsUH3DaC428xvtGD9_EuPFLSue0yrWja93yQ%40mail.gmail.com.