Yuval Kogman skribis 2005-10-07  3:02 (+0200):
> >     my Array $a = 97;      # dies eventually, but when?
> >     my Int   $b = 3.1415;  # dies at all?
> Both die at compile time, because the user explicitly contradicted
> him/herself. This is like saying
>       my int = $x :: float;

For my Int $c = $float, though, I'd want coercion.

And I think it is wrong to have such a huge difference between literals
and values: if a variable coerces, a literal has to do so too.

I believe that any value should be hardcodeable at any time, for testing
and debugging new code. Hard coding a value temporarily shouldn't
suddenly make the program die.

Otherwise we'll end up with more of the dreaded "my $dummy = ..."

> since they're constants and their types are very well known.

What is the type of 1.0?

I'd prefer all literal numbers to be Num and never Int (this doesn't
mean that this specific case can't be optimized to an Int).

Likewise, all literal strings should be Str, and all literal arrays
should be Array, and all literal hashes should be Hash. (Ignore for a
moment that the latter two are references.) The keyword here is "all" :)

> >     sub foo (Int $arg) {...}
> >     foo("hello");          # should die at the latest when foo() is called

There are two reasons to make this die, and I agree with only one of
them.

(a) Die because the argument passed is Str
(b) Die because "hello" can't in a useful way be coerced to a number

If it dies because of b, very good. If because of a, I think we have a
huge difference of opinion regarding automatic coercion.


Juerd
-- 
http://convolution.nl/maak_juerd_blij.html
http://convolution.nl/make_juerd_happy.html 
http://convolution.nl/gajigu_juerd_n.html

Reply via email to