On 1/26/06, Stevan Little <[EMAIL PROTECTED]> wrote:
> Actually this might not be a bad approach in this case. Take this for 
> instance:
>
> method foo (Foo $self, $key) {
>     ((Hash) $self){$key}
> }
>
> The syntax is ugly, but it makes what you are doing more explicit. I
> would also think that in most cases this could be compile time checked
> (if we can check $self's type (Foo), we can make sure Foo does/isa
> Hash).
>
> Here are some other ideas for a typecasting syntax using "as" for the
> keyword (which IIRC is taken for coercion??):
>
> $self as Hash {
>      # $self is treated as a Hash inside the block
>      $self{$key} = $value;
> }
>
> # it could also return a wrapped
> # $self for use in wider scopes
> my $h = $self as Hash;
> $h{$key} = $value;

Isn't typecasting a DesignSmell? This kind of overloading is, imnsho,
going to cause more coding bugs and is going to be considered a design
flaw in P6.

If there is need to treat something as a Hash, then provide it with a
postcircumfix<{}> and leave it at that. It's highly unlikely that you
will want to add Hash-like behavior to something that already has a
postcircumfix<{}> because it probably has that behavior already.

Rob

Reply via email to