Dave Storrs <[EMAIL PROTECTED]> writes: > On Mon, Dec 09, 2002 at 03:58:54PM -0700, Luke Palmer wrote: >> > From: Dave Storrs <[EMAIL PROTECTED]> >> > My understanding was that in Perl6, you could use pretty much anything >> > for a hashkey--string, number, object, whatever, and that it did not >> > get mashed down into a string. Did I have this wrong? >> >> By default they're keyed by strings. You can smack a property on them >> to key them by something else, though: >> >> my %sparse is keyed(Int); >> my %anything is keyed(Object); # or UNIVERSAL > > Hmmm...maybe this is a good time to bring up something that's been > bothering me for a while. > > It seems like Perl6 is moving farther and farther away from Perl5's > (almost) typelessness.
It depends what you mean by typed. Perl has always had strongly typed *values* (which strike me as being a damn sight more useful than typed variables). In a language with typed values, being able to declare a typed variable is useful for a few reasons: * After watching things in a profiler, you sacrifice programmer flexibility by typing a couple of variables as a way of giving the Optimizer something to get its teeth into (if you have a typed variable then you can limit the amount of runtime checking you have to do in favour of compile time checks) * For setting up multiply dispatched methods and functions. Consider the example below (which I know I've used before). sub grep ( (Rule | Block) $selector, @*args ) { @args.grep($selector) } sub grep ( (Rule | Block ) $selector, Collection $collection ) { $collection.grep($selector) } sub grep ( WeirdSelector $selector, @*args ) { grep $selector.as_block, *@args; } Because we can declare the types of the function parameters we can let the language sort out the dispatch for us. Without typed parameters and multi dispatch those three function definitions become: sub grep ( $selector, $first, @*args ) { if @args.length { return [ $first, @args ].grep($selector); } else { $first.grep($selector); } } method Object::grep ($self: $selector { [ $self ].grep($selector); } Which, to my way of looking at things is deeply ugly. * And last and least, for 'strictness'. Personally I think this is the least useful choice; the programmer sacrifices flexibility for having the compiler catch errors that would be more usefully caught in a test suite. And to make matters worse, if you want the compiler to catch the errors you have to make *everything* explicitly typed, and and life's too short for buggering about like that thank you very much. -- Piers