Talk:Language Comparison Table: Difference between revisions

Content added Content deleted
(→‎Perl 6 - Strongly typed: Is there more to it...)
(→‎Perl 6 - Strongly typed: yes, according to the definition given)
Line 188: Line 188:
:''Perl 6 is strongly typed; all apparent polymorphism/conversion is user-controllable''
:''Perl 6 is strongly typed; all apparent polymorphism/conversion is user-controllable''
What does the comment mean w.r.t. an expression like <code>'1' + 1</code>. Would it work? Are there interpreter options and/or program statements that could make it work/not work? Would it work 'by default'? I just have a thought that a fuller answer might be more than say the answers for Java, Haskel or Python. --[[User:Paddy3118|Paddy3118]] 20:47, 13 September 2011 (UTC)
What does the comment mean w.r.t. an expression like <code>'1' + 1</code>. Would it work? Are there interpreter options and/or program statements that could make it work/not work? Would it work 'by default'? I just have a thought that a fuller answer might be more than say the answers for Java, Haskel or Python. --[[User:Paddy3118|Paddy3118]] 20:47, 13 September 2011 (UTC)
:You left out the most salient bit of the comment, which was "by the definition provided". So my remarks should be taken in the context [http://rosettacode.org/wiki/Type_strength]. Also, if you are extrapolating from the weak semantics of Perl 5, forget that, because Perl 6 has a completely different type system.
:So let's look at <tt>'1' + 1</tt>. The term <tt>'1'</tt> is known to be of type Str, while the <tt>1</tt> is of type Int. These are both types with well-defined, implementation-independent sets of values. (They are not confused into scalar values as they are in Perl 5.) The default string type is a sequence of Unicode graphemes without arbitrary size limit. The default integer type is the set of all integers without arbitrary size limit. So we don't have the problem of undefined types or overflow that the definition points out in C, nor is there any implementation dependency. Conversion of string to number is required to complain about ill-formed numbers. Any conformant implementation of Perl 6 must support these semantics.
:The expression in question does work by default, but not because of any implicit coercion within the actual addition operator, well, operators, really, since they're multi subs, which have signatures that know how to add integers, rationals, floaters, etc. But they don't do implicit coercion; instead, we use "mechanisms resembling weak typing" to define allowable coercions. There is a specific generic signature that allows coercion of strings to numeric, after which the appropriate numeric operator is applied. These signatures are defined in a magical outer lexical scope called the setting, and are ostensibly written in Perl 6, apart from the places where circularity must be broken by use of primitives. (A setting is allowed to cheat as long as everything in the setting ''appears'' to be written in Perl 6.)
:Any or all such overloaded signatures may therefore be shadowed in an inner scope, including the coercive generic signatures. One of the strong design principles of Perl 6 is that every lexical scope know exactly what language it is using, where "exactly" does not preclude genericity, but only accidental genericity. Therefore lexical scoping is how we override anything in the outer language and produce a new language in an inner lexical scope. Since Perl 6 is designed to be completely mutable in this sense, such an inner language can appear to be as weakly typed as you like, but since all of the outer primitives are, in fact, strongly typed, Perl 6 is better characterized as strongly typed.
:But finally, I'd like to point out that the very first thing the definition in question says is that type strength is a "vague term". <tt>:-)</tt>