News for hackers. Stuff that matters.
Re:Golang Diaries: Generics by svnpenn on Sunday May 15, 2022 @09:58AM (#31387601)
> func (c *container>[S]) size() int {

This is not valid code.

Re:Golang Diaries: Generics by tapirl on Sunday May 15, 2022 @11:39AM (#31388221)
It is obviously a typo.
Re:Golang Diaries: Generics by timbray on Sunday May 15, 2022 @12:39PM (#31388730)
Yep, fixed, thanks.
Re:Golang Diaries: Generics by jallasprit on Sunday May 15, 2022 @10:03AM (#31387632)
This is one of the first things I remarked about the Go generics implementation. It is not yet possible to use Generics on struct methods.
Re:Golang Diaries: Generics by morelisp on Sunday May 15, 2022 @10:20AM (#31387716)
No, it's not valid because there's a trivial typo probably caused by bad HTMLification. Remove the > and it's fine.
Re:Golang Diaries: Generics by Strum355 on Sunday May 15, 2022 @10:20AM (#31387717)
Thats a separate issue from the one being shown here. The syntax here is just invalid
Re:Golang Diaries: Generics by Philip-J-Fry on Sunday May 15, 2022 @11:42AM (#31388237)
You can use generics, you just can't introduce new type parameters in the method. You're free to use the type parameters defined on the type you're writing the method for.
Re:Golang Diaries: Generics by fsdjkflsjfsoij on Sunday May 15, 2022 @10:19AM (#31387711)
The restriction of not introducing new generic types on methods has nothing to do with why that code doesn't compile. Remove the '>' in the method signature and it works fine.