[go-nuts] Re: [generics] Closure?

2020-06-18 Thread 'Bryan C. Mills' via golang-nuts
I think this is a bug in the parser, related to (but not the same as) 
https://golang.org/design/go2draft-type-parameters#instantiating-types-in-type-literals
.

Adding doubled parentheses seems to make it work 
(https://go2goplay.golang.org/p/JSQ_8kGOC_A), but the `Format` button 
doesn't preserve them.

I would recommend filing an issue per 
https://go.googlesource.com/go/+/refs/heads/dev.go2go/README.go2go.md.
On Thursday, June 18, 2020 at 2:18:48 PM UTC-4 teiva...@gmail.com wrote:

> Hello,
>
> I didn't find in the latest draft design any mention of generics with 
> closure and I'm struggling in having something working:
>
> type Foo(type T) struct {}
>
> func bar(type T)() Foo(T) {
>return func() Foo(T) {
>   return Foo(T){}
>}()
> }
>
>
> In this example, how can I create a closure that would return a *Foo(T)*?
>
> Here is the playground: https://go2goplay.golang.org/p/N-b10vSCois
>
> Cheers
>

-- 
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/472dc188-3b01-40bb-a56c-8c22f2782cf3n%40googlegroups.com.


[go-nuts] Re: [generics] Closure?

2020-06-18 Thread Bebop Leaf
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 considered as `(Foo T)`, which is named return.

This is mentioned partly at 
https://go.googlesource.com/proposal/+/refs/heads/master/design/go2draft-type-parameters.md#using-generic-types-as-unnamed-function-parameter-types.
 
But I think at lease it should be updated to include return value 
declaration.

-- 
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/e26bf937-74c3-4562-b1f4-a1ea34518943o%40googlegroups.com.