> I was not discussing such trivial cases.
>
> my A $a = read_an_A(); # May be of type AA which ISA A
> # but is not yet defined!
> $a->blah();
If read_an_A is not yet defined (or declared, in this case), then it's
an error (though it could be pragma-controllable:
undeclared_functions_assumed_to_be_of_correct_type)
If package A is not yet defined, then either my A is an error, or
$a->blah() is an error because it belongs to a type with an empty
signature (undefined, actually).
Whether package AA is defined is irrelevant. $a's static type is A, so
$a->blah() is an error iff A does not have blah() in its signature.
> > > > 2. run-time type checking
> > > > - it's still better to give a type error than to silently do something
> > > > unexpected. At least, if that's what you ask for. For example, it's
> > > > better than later complaining about an undefined method, since it
> > > > catches the original source of the problem and narrows down the set of
> > > > possible screwups.
> > >
> > > Like what? I do not see offhand how one would be able to provide a
> > > more meaningful error message.
> >
> > my Dog $d = new Dog;
> > my Cat $c;
> > $c = $d; # Cannot assign value of type "Dog" to scalar of type "Cat"
>
> Why? Never heard that we are going to prohibit this...
Maybe not. But we could. And if we want to do any form of typing, then
we pretty much have to -- otherwise, what's the point? Checking methods
only?
> > $c->purr(); # Can't locate object method "bark" via package "Dog"
>
> Aha, is it what we get now?
Well, no. Now, we'd get q(Can't locate object method "purr" via package
"Dog"). But hey, I was close! ;)
Yes, this is what we get now. My point was that this error is too late;
type information catches the error earlier.
> > my TwoDigitYear $x = 99;
> > sub years_to_go (FourDigitYear $) {
> > 2037 - shift;
> > }
> > print "There are ", years_to_go($x), " years until the year 2037!";
>
> Hmm, did we ever want to prohibit *this*? Via core hooks?
Core hooks? What are you talking about? This is straightforward
typechecking. $x was declared to be the type identified by the string
"TwoDigitYear". It was passed as a parameter to a function declared to
accept a parameter of type "FourDigitYear". strcmp("TwoDigitYear",
"FourDigitYear") != 0. Type error.
Thread Previous
|
Thread Next