On Sat, Apr 30, 2005 at 09:13:26AM -0500, Abhijit Mahabal wrote:
> On Fri, 29 Apr 2005, Brent 'Dax' Royal-Gordon wrote:
> 
> >David Storrs <[EMAIL PROTECTED]> wrote:
> >>Could we see some code that shows why this is a good idea?  My initial
> >>reaction is horror; I can very easily see huge numbers of subtle,
> >>hard-to-reproduce bugs coming out of this.  
> >>I'm quite willing to believe that there are [good results], but I'm not
> >>coming up with them.


> >What do you think this is?
> >
> >   sub foo(Str | Int $bar) { ... }
> 
> I believe you mean sub foo(Str^Int $bar){...} ( something that is Int or 
> Str but not both). But that, too, just reduces the amount of code and is 
> merely a shortcut for:
>       multi sub(Str $bar){...}
>       multi sub(Int $bar){...}
> 
> I do not see how any auto-threading occurs in that code. It is completely 
> innocuous in that sense, and I don't think that is what horrified
> David. 

Indeed, you're right on the money, Abhijit.  Thanks for stating it so
well.


Let's move this away from simple types like Str and Int for a moment.
Tell me what this does:


class Tree { 
      method bark() { die "Cannot instantiate a Tree--it is abstract!" }
}
class Birch { 
      method bark() { return "White, papery" }
}
class Oak { 
      method bark() { return "Dark, heavy" }
}
class Dog {
      method bark() { print "Woof, woof!"; return "bow wow" }
}
class AlienBeastie isa Tree isa Dog {}
class WhiteAlienBeastie isa Birch isa Dog {}
class HeavyAlienBeastie isa Oak isa Dog {}

sub Foo(Tree|Dog $x) { $x.bark() }


Ignore for the moment that this is stupid code--it's semantically and
(AFAIK) syntactically valid.  So, what happens when I do each of these:

        Foo( new AlienBeastie() );
        Foo( new WhiteAlienBeastie() );
        Foo( new HeavyAlienBeastie() );

??

--Dks

Reply via email to