HaloO,

Larry Wall wrote:
I don't think most people want to think of functions as types--it just
clutters up the type namespace.

Which contradicts their first-class status.


 They can already say:

    sub mysubuser ( &f where &mysub.sig ) {...}

or some such to do explicit smartmatching against the &f object.

Didn't where always require braces? And is where unary or binary?

  sub foo (Int where 0..10 $x) {...}

This looks more like the juxtaposition of the two constraints
'Int' and 'where 0..10' or is where binary there? Is the above
identical to

  sub foo ($x of Int where 0..10) {...} # note of

while

  sub foo ($x Int where 0..10) {...}

is a syntax error, that perhaps needs

  sub foo ($x where {Int 0..10}) {...}

and applys the constraint to the of type of $x. But that
contradicts your usage of where below. So this is more a
binary where that checks $x as a whole. But I have difficulties
to get a meaning from it. The only idea is that the above
fails along the lines that Int is incompatible with Scalar.
That is '$x where Foo' means that the implementation type of
$x has to be a subtype of Scalar just like '$x is Foo' demands
exactly the implementation type Foo.


Alternately if they really want the type they can say

    subset mysub of Code where &mysub.sig;
sub mysubuser ( &f where mysub ) {...} # note &
    sub mysubuser ( mysub $f ) {...}       # note $

That is structural subtyping. The thing I wanted was nominal
subtyping of functions. In the above &f is just constraint to
the &mysub.sig which drops the reference to the name. And we
already have a syntax for that

  sub foo ( &f:(Int-->Int) )  {...} # literal
  sub foo ( &f:(&mysub.sig) ) {...} # per reference,
                                    # perhaps needs flattening with |

The important point is how does one declare that a sub implements
the concept named by another sub:

  sub foo {...} # think: class foo

  sub bar is foo {...} # think: class bar is foo

To conflate sub and class should actually be easy because in the
background everything is an object anyway. This would e.g. allow
the has declarator in a sub:

   sub mul (Int $x)
   {
      has Int $.factor is rw = 1;

      return $x * $.factor;
   }

   &mul.factor = 2;

   say mul(3); # prints 6

I haven't thought that through but it might even be possible to
drop & as a sigil and get it as a prefix op.


Regards, TSa.
--

"The unavoidable price of reliability is simplicity" -- C.A.R. Hoare
"Simplicity does not precede complexity, but follows it." -- A.J. Perlis
1 + 2 + 3 + 4 + ... = -1/12  -- Srinivasa Ramanujan

Reply via email to