Re: is it required to use type declarations?
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
Re: Everything is an object.
On Tue, Dec 17, 2002 at 09:48:56AM -0500, Dan Sugalski wrote: Simon Cozens wrote: Once again we're getting steadily closer to inventing Ruby. Agreed, but I don't think this is necessarily a Bad Thing. Disagreed--we're getting steadily closer to inventing Smalltalk. :) Silly rabbit, Ruby is Smalltalk!
Re: is it required to use type declarations?
On Wed, Dec 18, 2002 at 09:31:41AM +, Piers Cawley wrote: Dave Storrs [EMAIL PROTECTED] writes: 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). No argument from me. When I want/need the abilities that come with specifying type, I want the language to support it. I just don't want to _have_ to do it, when I don't want/need those abilities. 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) Agreed. * 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); } Hm. I'm way short on sleep today, so I'm probably missing something, but I don't see why Perl can't sort this out without a specific typing. On a more nit-picky level, the first two subs in the top block seem to show that arrays are not derived from Collection. Surely, if everything is an object, they should be? Which, to my way of looking at things is deeply ugly. I certainly find the first version easier to read...which, given my particular set of prejudices, makes it enormously preferably in my eyes. * 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. Agreed. --Dks
Re: is it required to use type declarations?
Attribution lists are getting a bit complex. This is in response to what Piers wrote on Wed, Dec 18, 2002 at 03:50:44PM +. DKS [specifying types] Hm. I'm way short on sleep today, so I'm probably missing something, but I don't see why Perl can't sort this out without a specific typing. PC Well, you've got to specify the types *somewhere* when you set up your multimethods. The parameter list seems a better place than most. Ah! Ok, yes, I missed something. I thought you were saying that we would need to type the variables not just in the signature, but in every call to the function/method as well...and that second part is what I was objecting to. No, of course you need to mark the types in the signature. --Dks