On Fri, Mar 18, 2005 at 09:36:49PM -0500, Chip Salzenberg wrote: : Nobody on #perl6 today could answer this one. Is: : Str | Int where { $_ } : the same as: : (Str | Int) where { $_ } : or: : Str | (Int where { $_ }) : ?
"where" binds looser than |, but it's a member of a select group of operators that are considered declarational. You couldn't replace | with + there, for instance. : Followup questions, Mr. President: : : What kind of operators are "where", "of", "is", and "will"? They're basically keywords that are for use only in type declarations (where complex type names inside run-time expressions can be considered a form of anonymous type declaration, with some proviso that anonymous types declared similarly are considered structurally equivalent, for some definition of "similarly"). : Is there a reason that S03 doesn't list them? They aren't really operators in any general sense. : What are their precedence(s)? They might not actually have an official precedence if they're typically parsed top-down. We can say how they behave relative to the other declarational keywords, but they're sort of in a different world than the ordinary operators. Your Str | Int above could be considered a thunk that is forced to be evaluated at compile time. Anyway, "is" is what we call a "trait_auxiliary" because it introduces another identifier plus its associated argument, while "of" is what we call a "trait_verb" because it just takes an ordinary argument. The "is" is left associative in the sense that it always applies to the main thing being declared to its left, so a sequence of is clauses all refer to the same object. On the other hand, "of" is right associative and modifies the rightmost thing to its left. "will" is just a variant of "is" that parses its two arguments with the assumption that a closure is expected for the second one, but is otherwise identical in precedence and associativity. "returns" is an exact synonym for "of". Both of them parameterize the type to their left, though that type may be implicit in the cases where the variable doesn't have an explicit "is" type. That is, my @array of Int; is really short for my @array is Array of Int which is really something like my @array is Array[:returns(Int)] and because of right associativity, my @array is Array of Array of Int means something like: my @array is Array[:returns(Array[:returns(Int)])] As for "where", it probably associates like "of" and other trait verbs, though it means something different, associating a Selector with the leftward type rather than a return type. Larry