In fact I'd rather deal with the general issue by relaxing some rules, if it's something that is deemed worthy of being dealt with.
Basically if you have a map[interface{}]interface{} because you have a mixed bag of value that you fill at runtime, you cannot actually use any type you want as the key. Semantically, there is an additional constraint that I don't believe should exist. And it's on any type that has one or more fields of type slice/map/ or func. The alternative is to implement one's own associative array datastructure with one's own hashing algorithm etc but that's still going to be clunky since it will be implementation dependent and will rely on the use of unsafe. On Thursday, June 30, 2016 at 8:21:32 PM UTC+2, Konstantin Khomoutov wrote: > > On Thu, 30 Jun 2016 09:55:30 -0700 (PDT) > Chad <send...@gmail.com <javascript:>> wrote: > > > I understand the worry but the more I think about it, the less I > > think it would end up being a real issue. > > > > Taking the example of maps... two different maps that have not the > > same location in memory are never equal, especially since modifying > > one does not modify the other. It's easily explained. > > > > For slices, explaining that it's a view of an array, and views of > > different arrays are not considered equals, it would also be easily > > explained to a beginning programmer. > > > > Well it's merely food for thoughts. (but it would solve later issues > > in the usability of maps) > > I think you can get away using helper functions. > > Say, having > > type SliceKey struct { > Ptr unitptr > } > > func Key(s []byte) SliceKey > { > ... > } > > which would calculate whatever suits your needs from its parameter, > you could use it to actually turn your slices and maps into proper keys. > > Such a function can just use package unsafe to crack the slice header > value in whatever way it wishes (as in the piece of advice from Daniel > Skinner earlier in this thread). > > Working with a map would then look something like > > m := make(map[SliceKey]int) > > b := []byte{1, 2, 3} > > m[Key(b)] = 42 > > v := m[Key(b)] > -- 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.