TSa Thomas.Sandlass-at-barco.com |Perl 6| wrote:

Sorry, I see no contradiction. Method doit *is* a parametric type.
That is you need a type argument to make a code type. And then
you need args to make an invocation. Now the question is who provides
the type argument and when. An explicit instanciation would read

   doit[Int] 3: 3,2,1;

but the compiler might also infer this. Note that this has the
surprising effect of inserting doit into the HOW of the runtime
invocant. Question is how long this persists and what errors can
occur when the attempt is made. This is what I call a free method
and the Perl 6 grammar might actually forbid method definitions
outside of class bodies.
I did not see anything about "free methods" or the passing of type arguments in that manner to functions, in the synopses.

The usual circumstance of instanciating doit is in class composition

   role R
      method doit (::?CLASS $self: $a, $b, $c) { ... }

   class A does R
      # this is generated by the compiler
      method doit (A $self: $a, $b, $c) {...}

I do see that the use in a role is like a generic.

But you would use the sigil every time, e.g.

   method doit (::?CLASS $self: ::?CLASS $other --> ::?CLASS)

that is not three separate generics with conflicting names, but the same thing. With generics you can only use the sigil on the first use.

That is all methods in a role are parametric on ::?CLASS just
as all methods in a class are parametric on ::?SELF

   class B is A;

instanciates a new type &doit:(B $self: $a, $b, $c). This nicely

But doit is not a type. I think you were talking something like that earlier and I didn't follow.

Reply via email to