On Mon, Mar 22, 2021 at 2:10 AM Martin Leiser <leiser.1...@gmail.com> wrote: > > > What happens if > >I try to import a package that defines that Min function but I set the > >argument type to some that does not support the < operator? > I would simply write two similar packages: one using the above mentioned > enumerated interface of the accepted draft, > and another using the > type Lesser interface {Less(Lesser) Lesser } > The implementation of min with Lesser: > func Min(a, b Lesser) Lesser { if a.Less(b) {return a;} else {return b;}} > The implementation of Min with "ComparableStdType" stolen from the accepted > draft: > func Min(a, b ComparableStdType) ComparableStdType {if a < b {return a; } > else {return b;}
Sorry, I didn't phrase my question well. I wasn't asking how I can handle that case. I was asking how the compiler detects an erroneous use of the Min function with a type that does not support the < operator. But I gather that you are suggesting that we use type lists as in the current generics proposal, so that answers that question. If we do that, it seems to me that your proposal is no simpler than the current generics proposal. And I think that in practice it will be somewhat harder to use, because it ties generic type scope closely to package scope. I don't think it's the case that all generic types are logically tied to a package. Forcing them to be associated with packages will force people to break up their programs in unnatural ways in order to use generic types. 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/CAOyqgcW-xt__atkt6R%3DmjagXbCRu0pQcMKZ6gfJNxKNwgFXSCg%40mail.gmail.com.