On 2020-01-13 06:17, Brad Gilbert wrote:
According to the description you copied, a cardinal can never be zero.

     any of the numbers
     that express amount, as one, two, three, etc.

So it is more accurate to call it an integer.

Hi Brad,

Are you referring to "any of the numbers that express
amount, as one, two, three, etc."?  Zero and twelve
for that matter are covered by both the "Counting"
part and the "etc." part.  And by the way, I don't
care if you call them cardinals, unsigned integers,
counting numbers, or whatever are long as the
description is correct,

A "Counting Number" starts at zero.  It just can't
be a fraction or less than zero.

I think what is happening here is the way Raku declares
their Roles, Classes, Types, and Subsets:

https://docs.raku.org/type/Real
role Real
   Non-complex number
   role Real does Numeric { ... }
   Common role for non-Complex numbers.


https://docs.raku.org/type/Int
   class Int
   Integer (arbitrary-precision)
   class Int is Cool does Real { }
Int objects store integral numbers of arbitrary size. Ints are immutable.


https://docs.raku.org/type/UInt
   Subset UInt
   Unsigned integer (arbitrary-precision)
   The UInt is defined as a subset of Int:
   my subset UInt of Int where {not .defined or $_ >= 0};
   Consequently, it cannot be instantiated or subclassed;
   however, that shouldn't affect most normal uses

This would make the cardinal type of UInt an "Int"
with "Restrictions".  It also frees the high bit
for usage in the number.

This perfectly follows:
https://www.mathopenref.com/cardinal.html
   Cardinal numbers (also called whole numbers, natural
   numbers, or counting numbers) are those used to count
   physical objects in the real world, such as

      0, 1, 2, 3, 4 .....

   They are integers that can be zero or positive. They
   assume that the things being counted are not divisible.
   So we can have 4 cars, but never 3½ cars.

   Formally, counting numbers are the set of all
   non-negative integers.

   Cardinal numbers are also called counting numbers.
   ["$_ >= 0" from Raku]


So is Raku, a cardinal, called UInt in Raku, is a "subset
of Int" and a member of Int who is a member of Real.

No problem with any of that.  My ONLY problem is with the
error message.

What would make me happy would be if the error message
was changed from:

       This type cannot unbox to a native integer
to
       This type cannot unbox to subset UInt

-T


Now if we really, really wanted to make this thread annoying,
we would question why does Int belongs to Real:

https://www.mathopenref.com/real-number.html

      A real number is a value that represents any quantity
      along a number line. Because they lie on a number
      line, their size can be compared. You can say one
      is greater or less than another, and do arithmetic
      with them.

In other words, they can be fractions.  Integers can not.
But I am not going down that road.  Raku has it all perfectly
figured out.

And Real has a nice error message:
    $ p6 'my Real $r; $r = "XYZ";'
    Type check failed in assignment to $r; expected Real
    but got Str ("XYZ") in block <unit> at -e line 1

Reply via email to