On Mon, Aug 10, 2020 at 1:53 PM burak serdar <bser...@computer.org> wrote: > Would it be possible to make it explicit instead of trying to combine > builtin types and others? > > type Number interface { > type int, int8, int16, int32, int64, unit, int8, int16, int32, > uint64, float32, float64 > } > > func Min(type T Number)(a, b, T) { ... > } > > type Lessable interface { > func LessThan(interface{}) bool > } > > func Min(type T Lessable(T))(a, b T) { ... > } > > This would be similar to c++ template specialization. Specializations > could be limited to built-in types to limit ambiguity. > > }
There are two problems with this. First, it would require either a concept of "this or that" in interfaces, or duplicating all code that calls Min, however indirectly. This or that: type NumberOrLessable interface { // Satisfied by any type that satisfies either Number or Lessable Number | Lessable } func [type T NumberOrLessable](a, b, c T) T { return Min(a, Min(b, c)) } Or code duplication based on the interface that T satisfies: func [type T Number](a, b, c T) T { return Min(a, Min(b, c)) } func [type T Lessable](a, b, c T) T { return Min(a, Min(b, c)) } Second, Ian has long indicated strong opposition to specialization, as I think have others. -- 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/CAADvV_thEhOEmGjZR%2Bns4RVOS70UdZOhYs2r1fttgTFpbAFNtw%40mail.gmail.com.