At 11:57 PM -0500 12/16/05, Rob Kinyon wrote:
How many different undefs are there?
That depends on what exactly you are asking.
1. An undef is what you have when a container contains no explicit
value (or junction/etc thereof).
A variable whose value is undefined is still a typed container; eg:
my Int $z; # undef since not assigned to
my Str $y; # undef since not assigned to
my Any $x; # undef since not assigned to
my Foo $w; # undef since not assigned to
Each of those is a different container type, so in that respect each
is different from the others, but none of them has a value (they are
empty containers), so it doesn't make sense to try to use the value.
The container type specifies the domain of all possible values that
could potentially be put in the container, but none of them are in it
currently.
2. Until a value is put in a container, the container has the
POTENTIAL to store any value from its domain, so with respect to that
container, there are as many undefs as there are values in its
domain; with some container types, this is an infinite number.
Only a container that can have exactly one possible value can be
equated with; but then you have a constant.
In a manner of speaking, an undef is like a quantum superposition, in
that it has no specified value, but rather all possible domain values
at once, so you can not absolutely say it is equal to anything.
For all practical purposes, an undef is unuseable random garbage; its
only use is that you know it is currently undefined, and the
container holding it can later be given a defined value.
Taking this example (details may be incorrect):
my Int $x; # like -Inf..+Inf or something
my Int $y; # like -Inf..+Inf or something
$x == $y; # like random_one($x) == random_one($y)
$x == 3; # like random_one($x) == 3
The odds of two undefined values in such primitive data types being
equal is 1/Inf, which is zero.
So no 2 undefs are equal, and no undef is equal to a defined value.
You can't say what an undef equals because you don't know what value it has.
-- Darren Duncan