develooper Front page | perl.perl6.language | Postings from August 2001

Re: Will subroutine signatures apply to methods in Perl6

Thread Previous | Thread Next
From:
Damian Conway
Date:
August 23, 2001 17:03
Subject:
Re: Will subroutine signatures apply to methods in Perl6
Message ID:
200108240003.KAA02520@indy05.csse.monash.edu.au

Garrett asked:
 
   > Any word from on high whether subroutine signatures will apply to
   > methods in Perl6?
  
Well, I hardly qualify as "on high" ("on *a* high" perhaps?) but I can
definitely say this: They will and they won't.  ;-)

At compile-time, signatures can only be honoured if the compiler can
know about them. That will almost certainly require that the variable
holding the object reference be typed into an "interface" class (a la
http://dev.perl.org/rfc/265.html), and that the variables passed as
arguments be typed as well.

For example:

        class Canine is interface;

        sub bark_at(Canine $self, Feline $provocation) {...}

        class Dog;
        use base 'Canine';

        sub bark_at(Canine $self, Feline $provocation) {...}

	class Feline;

	class Cat;
	use base 'Feline';

        module main;

        my Dog $spot        = Dog.new;
        my $rover           = Dog.new;
	my Feline $fluffy   = Cat.new;
	my $felix;          = Cat.new;

        ...

        $spot.bark_at($fluffy);         # method sig checked at compile-time

        $rover.bark_at($fluffy);        # method sig checked at run-time
					# (type of $rover not known till then)

        $spot.bark_at($felix);          # method sig checked at compile-time
					# (type of $felix not known till then)

        $rover.bark_at($felix);         # method sig checked at run-time
					# (type of both not known till then)

One might also envisage a C<use strict 'typing'> pragma to require that
all lexicals be typed.

Damian

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About