Front page | perl.perl6.language |
Postings from April 2003
Re: Static typing with Interfaces
Thread Previous
|
Thread Next
From:
John Williams
Date:
April 17, 2003 14:19
Subject:
Re: Static typing with Interfaces
Message ID:
Pine.LNX.4.33.0304171458440.16412-100000@sharkey.morinda.com
> =head2 Fitting with other paradigms
>
> There are, of course, times when this doesn't work so smoothly. Certain
> interfaces can't be determined at compile-time. These include both objects
> whose methods may dynamically change, and those classes which delegate
> to an object of varying type.
>
> These I call "dynamic" types. Their behavior is too complex to be analyzed
> at compile-time, so they're just deemed with the "universal interface"
> (one that supports everything, with caveats) in the type checking phase.
> When run time rolls around, they may be checked on the spot or just run, in
> accordance with a pragma.
>
> If an object C<AUTOLOAD>s or specifies itself with an C<is dynamic> trait,
> it is considered dynamic. If an object derives from or delegates to
> an object of a dynamic class, it is also dynamic. The default polymorphic
> scalar is a dynamic type, because it delegates to its stored reference if
> it has one.
>
> When a dynamic object is assigned to a statically-typed variable, type checking
> just accepts it. At run time, the I<assignment> is checked for type
> compatibility, reducing bugs (and increasing efficiency) later on. This
> also applies to binding.
I interpret this section as agreeing that we need some way of specifying
when typechecking should be deferred until runtime. Whether it's called
"dynamic", "untyped", "relaxed", or whatever is not so important.
Besides assignment, we have to also consider method calls, and maybe other
things, such as return values and other parts of method signatures.
So hopefully this would give me a ParkingLot which can only store
Vehicles, but doesn't require me to typecast before trying to call the
.OpenDoor method on things I take out of the ParkingLot.
my @ParkingLot is Array returns (Vehicle is dynamic);
~ John Williams
Thread Previous
|
Thread Next