On 07/03/2015 10:02 PM, yary wrote:
> On Fri, Jul 3, 2015 at 3:03 PM, Timo Paulssen <t...@wakelift.de> wrote:
>> but this does not
>>> sub takes_int_array(Int @bar) { say @bar }
>>> takes_int_array([1, 2, 3])
>> because the type match is against the defined type. We do not
>> automatically infer that [1, 2, 3] could be a Positional[Int].
> How would one call "takes_int_array" with a literal [1,2,3]?  Can we
> declare it to be a "Positional[Int]" or create an object of that type
> in-line?

take_int_array( my Int @ = 1, 2, 3 );


Perl 6 types are, by default (and with some exceptions), not coercive.
If you declare a function to take an Int, and you try to call it with a
Str that happens to represent an integer, you still get a type error.

But one of the exceptions mentioned above is that assignment to an array
(or hash) variable is coercive in nature. 'my @a = 1, 2, 3;' works, even
though the RHS isn't an Array.

So when people write `sub sum(Numeric @a)`, they typically expect
coercive semantics from the parameter, because it's an array, right?
Instead they get the non-coercive rigor of a normal type constraint.

Which is why I tend to tell people not to use typed arrays -- they are
clumsy to use (by the standards that Perl 6 sets, at least), because
they seem to lack the magic of untpyed arrays.

Though "seem" is the key here: on assignment, they are just as magical
as normal arrays: 'my Int @a = 1, 2, 3' works as you would expect. It's
binding in a signature that surprises and frustrates people.

When we say 'sub take_int_array( Int @a )', we don't want an Int-typed
Array; we any array, and have the runtime validate for us that each
element is an Int. This interpretation (which is explicitly not what the
design docs state right now, nor what rakudo implements) would also make
sense with slurpies (Int *@a) and/or coercion types (Int() *@a).

Unfortunately, I have no idea how that could be realized, since binding
to a parameter binds the caller's object unchanged, pretty much by


yours ranting,

Reply via email to