Re: [go-nuts] Compile-time control flow with type inference

2024-11-04 Thread 'Axel Wagner' via golang-nuts
It's not clear to me, what W1 and R1 are in your example. But FWIW, Go has no way to do compile-time meta programming and is unlikely to ever get one. It interacts too poorly with the goal of predictably fast compile times and the general safety assumptions of Go (you can run `go build` and be sur

[go-nuts] Compile-time control flow with type inference

2024-11-04 Thread Mark Mavzon
Tried writing a poor man's union (sum) "type" using generic functions and recursion but found an issue. Here's the code: type nothing any type Or[V, R any] struct { value any rest any } func NewOr[V any]() Or[V, nothing] { return Or[V, nothing]{nil, nil} } func TypeOr[V, W, R any](or Or[W, R]) Or[

Re: [go-nuts] Generic type alias with type conversion

2024-11-04 Thread Ian Lance Taylor
On Mon, Nov 4, 2024 at 2:40 AM hey...@gmail.com wrote: > > Does that mean it's currently not possible to conditionally implement a > method based on type parameters? I think that is https://go.dev/issue/65394. Ian > On Monday, November 4, 2024 at 1:47:30 PM UTC+8 Ian Lance Taylor wrote: >> >>

Re: [go-nuts] Generic type alias with type conversion

2024-11-04 Thread tapi...@gmail.com
On Monday, November 4, 2024 at 1:47:30 PM UTC+8 Ian Lance Taylor wrote: On Sun, Nov 3, 2024 at 12:41 AM hey...@gmail.com wrote: > > Not sure generic type alias is the solution, but what I'm trying to do is I have a type like this > > type Map[K comparable, V any] struct { m map[K]V } > >

Re: [go-nuts] Generic type alias with type conversion

2024-11-04 Thread tapi...@gmail.com
Why do you have to use alias here? What is the problem if omap is not an alias? On Monday, November 4, 2024 at 6:39:51 PM UTC+8 hey...@gmail.com wrote: Thanks for the reply. Does that mean it's currently not possible to conditionally implement a method based on type parameters? And the solut

Re: [go-nuts] Generic type alias with type conversion

2024-11-04 Thread hey...@gmail.com
Thanks for the reply. Does that mean it's currently not possible to conditionally implement a method based on type parameters? And the solution should probably be that I use CanConvert from reflect do that at runtime? On Monday, November 4, 2024 at 1:47:30 PM UTC+8 Ian Lance Taylor wrote: > On