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
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[
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:
>>
>>
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 }
>
>
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
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