I liked the 'any' idea. It always felt to me a bit odd/not so clear
interface{} means anything.
Still, interfaces with type parameters for non generic code seems a mix of
behaviour and implementation description.
In all, looking forward to see these changes implemented to try them out :)
On Monday, 24 August 2020 at 08:09:15 UTC+2 rog wrote:
> On Mon, 24 Aug 2020 at 06:35, Denis Cheremisov <[email protected]>
> wrote:
>
>> 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)
>> }
>> }
>>
>
> This was discussed above.
>
> I don't believe you can do that. I didn't see any suggestion that knowing
> the type implies the ability
> to convert from the generic type to the known underlying type.
>
>>
>> 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
>> }
>> }
>>
>
> No. As proposed, the type switch doesn't change anything about the type T.
>
> Also, AIUI that type list wouldn't be very useful in practice, because
> using that interface type in the type list would only allow types whose
> underlying type is exactly Compare[T], which doesn't include any
> non-interface types or interface types that have more methods than just
> Compare.
>
> cheers,
> rog.
>
>
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/golang-nuts/64cb4261-5567-451e-b98a-5792b3adc36fn%40googlegroups.com.