HaloO,

Brandon S. Allbery KF8NH wrote:
  our ::T sub foo (T $a, T $b)

without needing to introduce a new twigil syntax for type variables.

My reading as well. But I would write it sub foo (::T $a, T $b --> T)
for better indicating that ::T is taken from the parameters.


(Although I would wonder if the whole ::-prefix thing is asking for trouble; it looks like scoping to me.)

Scoping? ::T is surely scoped for the body of foo only.


To me the foo looks like a template sub and I wonder how it is
instanciated with different types. Since type parameters are
provided with [] it should be foo[Int], foo[Str] and the like.
I wonder further if that could also be written foo of Str like
with Array of Int etc.

  my foo of Int &intfoo;

  my Int $x := intfoo(3,2); # type correct

Also I wonder if Perl 6 can support all foo[::T] with a single
generic body where other languages have to generate different
code for each ::T. The type inferencer could also find out a
lot of constraints for ::T from the body. E.g.

   sub foo (::T $a, T $b --> T)
   {
       if $a != 0 && $b != 0   # ::T does Compare[Num]
       {
          return $a * $b;      # ::T does Arithmetic
       }
       ...
   }


Regards, TSa.
--

The Angel of Geometry and the Devil of Algebra fight for the soul
of any mathematical being.   -- Attributed to Hermann Weyl

Reply via email to