News for hackers. Stuff that matters.
Re:Go generics draft design: building a hashtable by nemetroid on Wednesday June 17, 2020 @04:29PM (#23556345)
> For my design, I decided to enforce that both key and value types are comparable, so I could build a simple demo using two hashtables as an index and reverse index with flipped key/value types.

Surely the demo works equally well without this extra constraint? If the demo had a generic function for creating a reversible mapping it would have been necessary, but as it stands, this extra constraint comes across as avoiding having to write the less aesthetically pleasing

  type Table(type K comparable, V interface{}) struct {
    ...
Re:Go generics draft design: building a hashtable by mdlayher on Wednesday June 17, 2020 @04:35PM (#23556416)
Yep that is true. I wanted both values to be comparable for an easy demo but would write it as you've suggested if I intended to make this a general purpose package.
Re:Go generics draft design: building a hashtable by nemetroid on Wednesday June 17, 2020 @05:05PM (#23556740)
What I mean is that as written, the demo doesn't need V to be comparable.
Re:Go generics draft design: building a hashtable by mdlayher on Wednesday June 17, 2020 @05:24PM (#23556963)
Oh wow, for some reason I totally zoned out and finally understand what you mean. Yes, you're right! I should fix that.