golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
122.68k stars 17.49k forks source link

proposal: Go 2: generic type Inter int8,int16,int32,int64 #42139

Closed hqpko closed 3 years ago

hqpko commented 3 years ago
type Inter int8,int16,int32,int64

func Less(a,b Inter)bool{
  return a<b
}

// and
type UInter uint8,uint16,uint32,uint64
type Float float32,float64
type Number Inter,Uinter,Float

func Less(a,b Number)bool{
  return a<b
}
func Abs(n Number)Number{
  if n<0{return -n}
  return n
}
func Map(s []Number, f func(Number)Number)[]Number{
  r := make([]Number, len(s))
    for i, v := range s {
        r[i] = f(v)
    }
    return r
}

// sorter
type Sorter Number,string 
func Sort(list []Sorter){
  // ...
}

// even with interface
type Some interface{String()},string
mvdan commented 3 years ago

Please note that you should fill https://github.com/golang/proposal/blob/master/go2-language-changes.md when proposing a language change.

ianlancetaylor commented 3 years ago

How is this related to the design draft at https://go.googlesource.com/proposal/+/refs/heads/master/design/go2draft-type-parameters.md ? Thanks.

hqpko commented 3 years ago

sorry, I need to think more, closed