From: Jonathan Scott Duff <[EMAIL PROTECTED]>
   Date: Sat, 30 Sep 2006 17:23:54 -0500

   On Sat, Sep 30, 2006 at 11:48:04AM -0700, Joshua Choi wrote:
   > How does automatic coercion work? 
   [ deletia ]
   > 1. C<sum()> automatically coerces its C<Str> arguments into C<Num>
   > parameters because C<Str.does: Num>.

Wouldn't it be better to do the coercion explicitly?  E.g.:

  multi sum ( Str $addend1, Num $addend2 --> Num ) { sum 0+$addend1, $addend2 }
  multi sum ( Num $addend1, Str $addend2 --> Num ) { sum $addend1, 0+$addend2 }

After all, there may be more than one way to do the coercion, especially
for something more complicated than a number.

   > 2. C<say()> then automatically coerces its C<Num> arguments into
   > C<Str> parameters because C<Num.does: Str>.
   > ...Or am I completely off the mark?)

   I hope you're way off the mark. Automatic coercion was one of the
   annoyances I remember from C++. Debugging becomes more difficult when
   you have to not only chase down things that are a Foo, but anything
   you've compiled that might know how to turn itself into a Foo.

I tend to agree, FWIW.

                                        -- Bob Rogers

Reply via email to