TSa writes: > Dr.Ruud wrote: > > > What would be the way to define-or-set that a specific hash has > > non-case-sensitive keys? > > (2) A way to constrain a string to be case insensitive. > > subset CaseInsensitive of Str where { .lc eq .uc } > > but it actually is a constraint on the &infix:<eq>, not on > the strings. So I doubt that it works as expected.
That depends on ones expectations! At best I'd expect that to be a set of digits, symbols, and all the other characters which don't have distinct upper- and lower-case forms. > But then I'm not sure if one can make subsets of operators at all: > > subset CaseInsensitive of eq where { .lc eq .uc } I wouldn't've thought so. > I guess you have to simply define CaseInsensitive as an alias---that > is an unconstraint subset---and overload &infix:<eq>. Then the hash > hopefully uses this operator when its key type is CaseInsensitive. But why would a hash be doing equality operations at all? Assuming that a hash is implemented efficiently, as a hash, then it needs to be able to map directly from a given key to its corresponding value, not to have to compare the given key in turn against each of the stored keys to see if they happen to match under some special meaning of eq. You snipped Ruud's next bit: > > Or broader: that the keys should be normalized (think NFKC()) before > > usage? That seems the obvious way to implement this, that all keys are normalized (say with C<uc>, for this specific example) both on storage and look-up. Then the main hashy bit doesn't have to change at all. Many people have implemented such a thing using tied hashes in Perl 5. So I guess you'd do the equivalent thing in Perl 6, whatever that is -- I've had a quick flick through the synposes and couldn't spot anywhere that mentioned the obvious hooks for the Perl 5 C<FETCH> and C<RESTORE> subs. Smylers