On 11/17/2010 10:08 PM, Martin D Kealey wrote:
Dimensioned numbers as restrictive types are useful, for uncovering bugs,
including sometimes latent ones in ported code.
Duration is a fairly clear example of a dimensioned quantity, and I think we
should think twice about abandoning its dimensionality, and the
restrictions that implies.
If using strict dimensioned quantities, the restriction would not be
that you cannot square it: it would be that you cannot assign the
squared duration to an incompatible lvalue; and cannot add it to a value
that is not also a squared duration. Thus
use strict <dimensions>; # strict should be default in p6?
my Duration $x = ...;
sleep $x; # OK
my $y = $x ** 2; # OK
sleep $y; # error (no candidate for dispatch)
my $z = $x + $y; # error (dimensionality mismatch)
The question, to my mind, is how to implement a "no strict <dimensions>"
pragma. perhaps all dimensioned quantities would implement a role, that
the pragma would tweak, to add implicit conversions to/from Numeric.
I do think that the dimensionality of Duration needs to be in the
context of a broader framework.