At 10:03 AM -0800 1/17/07, Jonathan Lang wrote:
TSa wrote:
Luke Palmer wrote:
That is, is 1 different from 1.0?
I opt for 1 being Int and 1.0 being Num. But for the
latter a test .does(Int) might succeed on the footing
that the fractional part is zero, that is 1.0%1 == 0.
I'm very leery of the idea that "A.does(B)" ever returns true when
role A does not compose role B; and my understanding has been that Int
does Num, not the other way around.
I think that 1 should be an Int and 1.0 should be a Num. That makes
things very predictable for users, as well as easy to parse ... the
visible radix point indicates that you are usually measuring to
fractions of an integer, even if you aren't in that exact case. Also
importantly, it makes it easy for users to choose what they want.
For round-trip consistency, a generic non-formatted
num-to-char-string operation should include a .0 as appropriate if it
is converting from a Num, whereas when converting from an Int it
would not.
Furthermore, my preference is for Int and Num to be completely
disjoint types, meaning that "1 === 1.0" will return False. However,
every Int value can be mapped to a Num value, and so "1 == 1.0" will
return True as expected, because == casts both sides as Num.
As for which .does which, I would use the relationship between Str
and Int|Num as an example. AFAIK, Int|Num .does Str, but not the
reverse. Similarly, Int should .does Num, but not the reverse. This
is all assuming that the purpose of .does is to indicate when values
of one type can be substituted for values of another type.
Similarly, if there is no .does relationship between Int|Num and Str,
due to what .does is actually for, then there shouldn't be one
between Int and Num.
-- Darren Duncan