HaloO,
John M. Dlugosz wrote:
Here is a sample:
<http://www.dlugosz.com/files/1.pdf>
There you write:
class C { ... }
class D is C { ... }
my C $c1; # creates container with actual value type of C
my D $d1 := $c1; # OK, since D “isa” C.
my C $c2 := $d1; # compile-time error, since static types
# are compared
my C $c3 := $d1 :coerce; # OK at compile time because test
# explicitly deferred to run time.
isn't that the wrong way around? D isa C and so you can bind
$c1 := $d1 and call C methods on $c1 which potentially are
re-implemented in D. However the static type C of $c1 should
prevent calls of D methods at CHECK time.
my Int|Str $x1;
my Int $x2 := $x1; # error, since could get Str’s out
# depending on actual value
my Int $y1;
my Int|Str $y2 := $y1; # error, since could put Str’s
# into container of Ints
This hinges on the details how binding works. If it is pure
name lookup then you can bind only variables of equal type.
But $Larry has the idea of $x1 and $x2 being different views
of the same underlying item. E.g.
$x2 = " 2.010 ";
my Num $x3 := $x2;
say "x1 = ($1); x2 = ($2); x3 = ($x3)";
prints "x1 = ( 2.010 ); x2 = (2); x3 = (2.01)". That is
the chars of the original string are preserved in the Int|Str
view but lost in the Num or Int view. The latter is also
flooring away the fractional part. Some of the consequences
are that
$x1 ne $x2
$x1 != $x2
$x1 == $x3
but of course
$x1 =:= $x2 =:= $x3
but note that after
$x1 = 42;
we now have
$x1 eq $x2
$x1 == $x2
$x1 == $x3
The Int constraint of $x2 means of course that $x2 = 'xx' is
an error, but $x1 = 'xx' is legal and *indistinguishable*
from $x1 = 0 for $x2.
my Int $x3 := $x1 :defer; # OK, fetches checked at run-time
my Int|Str $y3 := y1 :defer; # OK, stores checked at run-time
my Int $x4 := $x1 :coerce; # fails at run time because actual
# container type still wrong
my Int $x5 := $y2 :coerce; # type check agrees at run time.
# (The :coerce and :defer adverbs to := is proposed)
With the view paradigm these adverbs are obsolete I guess.
Regards, TSa.
--
The Angel of Geometry and the Devil of Algebra fight for the soul
of any mathematical being. -- Attributed to Hermann Weyl