On Tue, Jan 30, 2007 at 06:02:59PM +0100, TSa wrote: : How are coercions handled when calling functions? : : sub identity ( Int $i ) { return $i } : : my Num $x = 3.25; : : say indentity($x); # prints 3 or type error? Or even 3.25? : : I'm opting for type error on the footing that Int <: Num and : you can't allow a supertype where a subtype is expected.
Num-to-Int autocoercion is an explicit exception built into the language. Perl 5 programmars would lynch us if we broke it. But yes, it's basically cheating. We also cheat and autocoerce Str-to-Num and Num-to-Str all over the place. :) The interesting question is how this autocoercion is best declared. We've batted around several ideas on that in the past, but the general feeling is that it should only be applied to these basic everyday types, and that exotic types should not generally autocoerce unless you've explicitly declared a multi to handle the situation. Larry