HaloO,

Autrijus Tang wrote:
[..much better explaination of the co/contra prob then mine skipped..]
Hence, my proposal is that Perl 6's generics should infer its variancy,
based on the signature of its methods, and derive subtyping relationships
accordingly.

Yes!! That would be great. But I would restrict it to the onboard methods
or however we call them. Outside/free methods specialized on the generic
type are firstly referential in nature, and as such bind their $.attr,
@.array, %.hash and &.code referential expressions through the invocant.
They form a mediator layer between unrelated code and the code
implementing the type's guts.


The other alternative is do as Java does, which is assume invariancy by
default, then force users to write variancy annotations, but I think
that is considerably less attractive.  There may be a case for inferring
by default, but overridable by the user; if so there needs to be a
syntax for that.

Well, that pivots around how refs behave. I would opt for them beeing
const unless explicitly allowed :rw by the instance owner. Is the syntax
for that actually \$x:rw? Or even plain \$x if we assume that every sigil
expression *always* means implicit const ref? And thus needs a
dereferencer, e.g. $x()? Then

   $x  = $y; # means dispatch to op =
   $x := $y; # same, but op := requires $x to be writeable
  \$x  = $y; # same as := ?  I prefer \$x:rw which might fail
             #               depending on where $x refs to
  \$x := $y; # ???

Consider

   $x = [EMAIL PROTECTED]; # assume there's no slot 42, then the array could
                     # hand-out a \.[42]:rw and allow subsequent
                     # assignment
   # but

   $x = [EMAIL PROTECTED]; # assume .[23] is filled, then the array returns
                     # a const ref

Such an array would be typed Array of ::T^Ref:rw[Undef of ::T]
and as such a hot candidate for the default array :)
--
$TSa.greeting := "HaloO"; # mind the echo!

Reply via email to