Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Lexical scope of parametric declaration blocks

6 views
Skip to first unread message

Ashley Winters

unread,
Dec 7, 2004, 6:40:24 PM12/7/04
to Perl 6 Language
In S12, I see examples like:

role Pet[Type $petfood = TableScraps] {
method feed (::($petfood) $food) {...}
}

I assume that means lexicals declared as part of a parametric
specialization declaration block thingy are only visible within that
scope, like a formal subroutine parameter list?

If so, are there things allowed (or disallowed) in type parameter
lists vs. sub parameter lists?

If [] is enforcing long-name generation or something simple like that,
could I cheat and make it imply multi on my functions if I use it?

sub foo[Int $x: Pair ?$y] {...}
sub foo[Pair $x, Pair $y] {...}

Would that be valid/mean anything?

Okay, that enough curiosity for today. :)

Thanks,
Ashley Winters

Luke Palmer

unread,
Dec 7, 2004, 11:55:40 PM12/7/04
to Ashley Winters, Perl 6 Language
Ashley Winters writes:
> In S12, I see examples like:
>
> role Pet[Type $petfood = TableScraps] {
> method feed (::($petfood) $food) {...}
> }
>
> I assume that means lexicals declared as part of a parametric
> specialization declaration block thingy are only visible within that
> scope, like a formal subroutine parameter list?

Well, "like" is a pretty strong word, but it turns out not to be strong
enough in this case. It *is* a formal parameter list. It just isn't on
a sub.

The brackets are there to be visually distinctive. We like declarations
to look different from statements, and we like to know when we're
messing with parametric types.

> If so, are there things allowed (or disallowed) in type parameter
> lists vs. sub parameter lists?

Hmm... not that I can think of right off the bat.

> If [] is enforcing long-name generation or something simple like that,
> could I cheat and make it imply multi on my functions if I use it?
>
> sub foo[Int $x: Pair ?$y] {...}
> sub foo[Pair $x, Pair $y] {...}
>
> Would that be valid/mean anything?

I don't think you can do that. The brackets are kind of like C++'s
templates, but not really. Since Perl is dynamic, they're not really
saying anything is compile-time or anything like that. The brackets are
just like the parentheses, except you use them with types.

The big issue about these things that needs to be hashed out is type
equivalence. When are two parameterized types the same one? When their
arguments are exactly the same? What if the arguments don't know what
equality is? What if you have multiple signatures for usability, but
they map to the same logical type.

Luke

0 new messages