I probably didn't read what you have wrote in the first message carefuly 
enough. Does it mean something like that will work

    type SomeTypes interface {
    type int, float32, float64
    }

    func Min[T SomeTypes](x, y T) T {
        switch T {
        case int:
            if x < y {
                return x
            }
            return y
        case float32:
            return math.Min(float64(x), float64(y))
        case float64:
            return math.Min(x, y)
        }
    }

Would something like below work as well?

    type Compare[T any] interface {
        Compare(x, y T) int
    }

    type CompareConstraints[T any] {
        type int, int8, …, float64, string, Compare[T]
    }

    func Min[T CompareConstraints]Min(x, y T) bool {
        switch T {
        case int:
            …
        …
        case Compare[T]:
            return x.Compare(y) < 0
        }
    }

понедельник, 24 августа 2020 г. в 06:40:52 UTC+3, Ian Lance Taylor: 

> On Sun, Aug 23, 2020 at 3:00 PM Juliusz Chroboczek <j...@irif.fr> wrote:
> >
> > > We’re going to permit type switches on type parameters that have type
> > > lists, without the “.(type)” syntax. The “(.type)” syntax exists to
> > > clarify code like “switch v := x.(type)”.
> >
> > Could you please give an example of the proposed syntax?
>
> func F[T constraints.Integer]() {
> switch T {
> case int:
> case int8:
> }
> }
>
> 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 golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/4e9391f0-f688-4189-8822-39fc8e217b70n%40googlegroups.com.

Reply via email to