in reply to Re^9: Strong typing and Type Safety.A multilanguage approach (implicit)
in thread Strong typing and Type Safety.A multilanguage approach

[ Flawed premise: I was working from an incorrect definition of coercion. ]

I agree; that's why I try to prefer the term "coercion".

Coercion is not the same thing as conversion. How can you coerce the choice of operators if the operator is monomorphic? There can't be coercion for monomorphic operators since there is nothing to coerce.

There are two "=" operators, and you can coerce the choice of assignment operators.

$x = foo(); # scalar assignment operator ($x) = foo(); # list assignment operator

but what's the difference between:

In one, you used ->to_int (explicit conversion), in the other you didn't (implicit conversion). No coercion occurs since neither subs nor the "+" operator are polymorphic in Perl.

Replies are listed 'Best First'.
Re^11: Strong typing and Type Safety.A multilanguage approach (implicit)
by chromatic (Archbishop) on Nov 22, 2010 at 04:08 UTC
    How can you coerce the choice of operators if the operator is monomorphic?

    I have no idea what you mean. The evaluation of the operands coerces an SV to an IV, of course.

    implicit conversion

    I don't understand this logic. How is explicitly using a monomorphic operator which operates on numeric values any less explicit than performing a manual conversion operation through a method?

    (I don't accept the "But it's easy to make a typo when using an operator!" argument because it's easy to make a typo when calling a method.)

      How is explicitly using a monomorphic operator which operates on numeric values any less explicit than performing a manual conversion operation through a method?

      The addition operator operators on scalars, not numeric values; you can pass it a string if you so desire. The operator must coerce the string into a number in order to do the addition.

      The latter is explicit by definition. "Manual" is synonymous with "explicit".

      Implicit conversion is less explicit than explicit conversion.

        The addition operator operators on scalars, not numeric values; you can pass it a string if you so desire. The operator must coerce the string into a number in order to do the addition.

        From perlop:

        Binary "+" returns the sum of two numbers.

        The operator is monomorphic. Again, how is using the binary numeric addition operator not explicit about the intention to treat its operands in a numeric fashion?

      ok, it seems I had the wrong definition for coercion. According to wikipedia, "coercion" is simply another way of saying "implicit conversion" ("in most languages", it adds).