Austin Hastings wrote:

In this case, I rather like the idea of being able to say

sub foo(@a is Array of Int) {...}

   my @input = read_a_bunch_o_data();
   foo(@input);


Where the compiler will automatically "wrap" the @input array in a make-it-an-int converter. This, to me, is DWIM.

But to many others it's not DWIS ("Do What I Said"). To them, types are about compile-time checking of constraints on the run-time compatibility of data.
So they would argue that declaring C<foo> like that implies that any argument passed to C<foo> ought to guarantee that it already contains Ints, rather than specifying a (possibly unsuccessful) run-time coercion to ensure that condition. And many would argue that implicit coercions on typed parameters is one of the major *problems* with C++.


My own problem with this wrapping notion is that I consider it incompatible with the reference semantics of normal Perl 6 parameters. Specifically, I *don't* want the aliasing mechanism to be capable of implicit type coercions.

On the other hand, I have *no* problem with this:

        sub foo(@a is Array of Int is copy) {...}
                                   ^^^^^^^

doing the kind of coercive wrapping you're suggesting.


Connecting this with some thinking/talking about wrappage, it occurs to
me that:

C<call> is just a keyword. Which means that instead of doing

foo.wrap({ ...; call; ... });

That has to be:


&foo.wrap({ ...; call; ... });


I could just as easily do:

sub wrapper(...) { ...; call ; ... }
foo.wrap(&wrapper);

Right?

&foo.wrap(&wrapper);


But, yes.


I think there may be a library of wrapper "helper-functions" used by
both the compiler and module-writers. Things that do coercive behavior
rather than try-but-maybe-fail behavior.

Quite possibly. Though wrapping is probably too "heavy" a mechanism for type coercions. When I imagine type coercions in Perl 6, I imagine them as compile-time detectable, and explicit.



So the "use strict signatures;" wouldn't be a switch invoking type
stricture, per se. What it would do is convert from "DWIM stricture" to
"Patriot Act stricture".

I still believe that the default level of type-checking you're proposing is the wrong way round.


Damian




Reply via email to