On Sun, 27 Feb 2005 02:20:59 -0700, [EMAIL PROTECTED] (Luke Palmer) wrote: > Luke Palmer writes: > > Autrijus Tang writes: > > > Just a quick question: Is Hash keys still Strings, or can they be > > > arbitary values? > > > > They can be declared to be arbitrary: > > > > my %hash is shape(Any); > > > > > > > If the latter, can Int 2, Num 2.0 and Str "2" point to different > > > values? > > > > That's an interesting question. Some people would want them to, and > > some people would definitely not want them to. I think the general > > consensus is that people would not want them to be different, since in > > the rest of perl, 2 and "2" are the same. > > I forgot an important concretity. Hashes should compare based on the > generic "equal" operator, which knows how to compare apples and apples, > and oranges and oranges, and occasionally a red orange to an apple. > > That is: > > 3 equal 3 ==> true > 3 equal { codeblock } ==> false > 3 equal "3" ==> true >
I would have assumed a hash who shape was defined as C<Int> to perform the hashing function directly on the (nominally 32-bit) binary representation Int 2. Likewise, c<my % hash is shape(Double)>, would perform the hashing on the binary rep of the (nom.64-bit) Double value. And C<my %hash is shape(Ref)>, on the address of the key passed? By extension, a C<%hash is shape( Any )> would hash the binary representation of whatever (type of) key it was given, which would make keys of 2, 2.0, '2', '2.0', (Int2)2 etc. all map to different keys. If C<%hash is shape(Any)> maps all the above representation of 2 to the same value, then C<my %hash is shape(Any)> becomes a synonym for C<%hash is shape(Scalar)>. (is that the same as C<my %hash of Scalar>?). If my auumption is correct, then that would imply that each type hash or inherits a .binary or .raw method to allow access to the internal representation? > Luke