This is a hypothetical question. Suppose generics were implemented as in the draft proposal, but without contracts. Instead, the rule is that if an instantiation of a generic function with a specific type argument doesn't compile, then it can't be used.
Under those circumstances, is there any way to write a function func Min(type T) (a, b T) T {...} that returns the smaller of its two arguments, and meets _all_ of these criteria? 1) If a specific type X has a suitable Less() method, then Min(X) uses that. 2) Otherwise, if the < operator can be applied to X, then Min(X) uses that. 3) Otherwise, any use of Min(X) fails to compile. (A run-time panic does not satisfy this criterion.) By "X has a suitable Less() method", I mean that this function should compile successfully: func XMin(a, b X) bool { return a.Less(b) } I'm fairly sure there's no way to write Min, but perhaps someone can prove me wrong? (With contracts I'm doubly sure it can't be done, as the contract for Min would have to permit both Less and <, so then Min(X) would only be allowed for types X having both Less and <.) -- 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. For more options, visit https://groups.google.com/d/optout.