3 ms·
What do you think of the Perl 6 approach of providing both DWIM (weaker) and DWIS (stronger) typing? * Numeric and string operators are kept distinct. For exam
by raiph 10y ago
What do you think of the Perl 6 approach of providing both DWIM (weaker) and DWIS (stronger) typing?
* Numeric and string operators are kept distinct. For example `+` means numeric addition, never concatenation or some other string operation. To compare two strings, use `eq`, to compare two numbers use `==`. Etc. This sets things up nicely for supporting both DWIM and DWIS typing.
* DWIM typing: If you write something like `a + b`, you always get numeric addition. If need be the compiler tries to coerce `a` and `b` to numbers. `"12"` or `" 12" will both successfully coerce to 12. `"123foo"` and `"bar456"` will fail to coerce. If the coercion fails the program crashes at run-time.
* DWIS typing: To tighten type checking, add a type constraint. For example, `my Numeric (\a, \b) = ...` ensures that `a` and `b` only ever contain a numeric value.