The UInt
is defined as a subset of Int
:
my of Int where ;
Consequently, it cannot be instantiated or subclassed; however, that shouldn't affect most normal uses.
Some examples of its behavior and uses:
say UInt ~~ Int; # OUTPUT: «Trueâ€Â»my UInt = 0xffff_ffff_ffff_ffff_ffff_ffff_ffff_ffff; # 64-bit unsigned valuesay .base(16); # OUTPUT: «FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFâ€Â» (32 digits)++;say .base(16); # OUTPUT: «100000000000000000000000000000000â€Â» (33 digits!)my Int = ;say .base(16); # same as abovesay .^name; # OUTPUT: «Intâ€Â» - UInt is a subset, so the type is still Int.say .^name; # OUTPUT: «Intâ€Â»# Difference in assignmentmy UInt = 5; # nothing wrongmy UInt = -5; # Exception about failed type checkmy UInt = 0;--; # Exception againCATCH ;# OUTPUT: «X::TypeCheck::Assignment: Type check failed in assignment to $b; expected UInt but got Int (-5)â€Â»# Non-assignment operations are finemy UInt = 0;say - 3; # OUTPUT: «-3â€Â»