Darren Duncan wrote:
Strong typing in Perl means that Perl is conveniently and reliably keeping track of this user-intended interpretation of the data, so it is easy for any piece of code to act on it in a reasonable way. Strong typing lets user code be clean and understandable as it doesn't have to do a lot of manual book keeping or error checking that Perl can do for it, such as detecting the error of passing a character string to a numeric multiplication operator.

First I have a question to the example of the behavior of a string
in a multiplication. Perl 6 automatically attempts a numerification.
But does that result in a failure for 'foo' or does that return 0?
That is, '3' * 3 == 9 is well formed and 'foo' * 3 is malformed, right?

This convenient and reliable book keeping to me means that there
are points in the execution sequence where type constraints are
checked. E.g. the constraint of a container is checked in an assignment.
But this must be seen as very different to the implementation types
of objects returned by WHAT. E.g. Bool, Bit, UInt and int8 are not
WHAT types. The int8 might be special because there could e.g. be an
overloaded optimized version of infix:<+> where 127 + 1 == -128 stays
within the valid range albeit with funny semantics.

One approach to enums is that their WHAT is simply Int. But this
has got the drawback that there can be unwanted accidental equalities
that otherwise would indicate an error.

   enum A « :One(1), :Two(2), :Three(3) »;
   enum B « :One(1), :Two(2), :Three(3) »;

   if A::One === B::One { say "accidental equality!" }
   if A::One === 1 { say "wanted equality?" }

   if A::Two == 2 { say "wanted numeric equality!" }

   multi sub doit (Int $x) {...}
   multi sub doit (A   $a) {...}
   multi sub doit (B   $b) {...}

This multi is only allowed if A and B are types distinct from Int which
to me implies that enums have a WHAT that is not Int. Opinions?

A further question is which operators are automatically generated for
enums. Does

   my Int $a = A::One;

increment from A::One to A::Two or to the Int 2? What shall happen
when A::Three is incremented? Failure or switch to Int? What happens with non-continuous enums? My vote would be to not generate any
operators with the consequence that

   my A $a = A::One;

fails when the Int 2 shall be written back into $a. I wonder if the
auto-generation of operators can be requested as follows:

   enum A « :One(1), :Two(2), :Three(3) » does Int;

Regards, TSa.

"The unavoidable price of reliability is simplicity" -- C.A.R. Hoare
"Simplicity does not precede complexity, but follows it." -- A.J. Perlis
1 + 2 + 3 + 4 + ... = -1/12  -- Srinivasa Ramanujan

Reply via email to