develooper Front page | perl.perl6.language | Postings from July 2005

Re: How do subroutines check types?

Thread Previous
From:
TSa
Date:
July 19, 2005 08:30
Subject:
Re: How do subroutines check types?
Message ID:
42DD1C90.3010107@orthogon.com
Ingo Blechschmidt wrote:
> How do I have to annotate the type specification in the 
> declaration of the subroutine to not include the class Foo, but 
> only allow instances of Foo? 

My understanding is that Foo.does(Foo) is false and sub params
are checked with .does(). This automatically excludes class args.
That is you have to explicitly order them:

sub blarb (Foo|Class[Foo] $foo, $arg) # or with CLASS[Foo] ?
{
    ...;   # Do something with instance or class $foo
}

Foo|Class[Foo] is a supertype of Foo and Class[Foo] and as
such allows its subtypes Foo and the Class[Foo] parametric
role instanciation. Note that Foo|Class allows calls like
blarb( Int, "HaHa" ).

Actually I'm not convinced that class Foo should automatically
constitute a (proper) type other than Any. But since .does falls
back to .isa it comes out the same since the only way here to get
a Foo doer is by instanciating the class Foo.
-- 
TSa (Thomas Sandlaß)



Thread Previous


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