On Mon, Sep 17, 2018 at 2:43 PM, Michael Jones <michael.jo...@gmail.com> wrote: > > Firstly, my compliments to Russ, Robbert, and Ian, for patience, > thoughtfulness, and insight. Whatever the best answer is, no doubt your > intellectual process is an excellent way to find it. > > My comment is a meta-comment, a question/proposal: if generics arrive in Go > 2 then can we "go fix" Go 1 code to use this mechanism to replace the > existing built-in magic generics in Go? > > For example, if it is possible to implement map in ordinary library code, > then should it be the rule to do so? The heop is that accepting this as the > test for goodness simultaneously proves capability and reduces the instances > of magical compiler support in favor of a new orthogonal feature, perhaps > making Go 2 conceptually smaller, which seems a good goal.
I agree that any reasonable generics proposal should be able to replace the magic generic functions and types in principle, but there are some issues. 1) The generic map/slice/array types have special syntax. While a generic data type should be able to provide the same functionality, there is no reason to expect that a generics proposal will support the same syntax. 2) The generic map type relies on the runtime package supplying a hash function suitable for any comparable type. Unless the generic proposal supports relatively complex template specialization, it would likely have to implement that hash function using the reflect package. 3) The append and copy functions permit appending/copying a string to a []byte. While it would be nice to be able to implement that generically, I don't think it's a requirement. 4) The make and new function are generic but use a special syntax. While a generic proposal should be able to implement those functions, it may not be able to emulate the syntax. The effect of all this is that even with generics it may not be possible to eliminate the existing generic types and functions. 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. For more options, visit https://groups.google.com/d/optout.