> Your proposition merely moves the semantical constraint to another 
> place: as Ian pointed out, if we define equality for slices to be 
> something resembling pointer equality suddenly []byte{1, 2} is not equal 
> to []byte{1, 2}. 
>

They are not since creating a slice allocate a different underlying array 
each time. They are not views on the same array.
It is merely incidental that on the example that is given, the two arrays 
have the same first and second elements. 

As discussed above, there is no semantic problem that has really been 
pointed out. 
It's a mere comparison of the slice header, a mere value comparison. Just 
as what would be done for any other type.

 

> The approach I have proposed (a custom "keying" function) is actually 
> what "every other language" does, just more explicit.  Say, .NET's 
> collections rely on their members implementing various interfaces such 
> as IHashCodeProvider.  My "keying" function merely provides a mapping 
> from values which cannot be used as keys directly to some other values 
> which can -- using your own rules.  Since your rules would be codified 
> explicitly, there would be no cognitive burden for the next programmer 
> reading your code. 
>
> > 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. 
>
> I propose putting such "hashing algorithm" outside of the datastructure. 
>
> Basically what I propose is replacing 
>
>   collection(K → V) 
>
> with 
>
>   collection(K' → V) 
>
> where K' is derived from K using your own function: K' = fn(K). 
>
> The collection stays unmodified, you just transform its keys. 
>

There is no real need for another indirection in Go. It's really 
straightforward.

-- 
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.

Reply via email to