[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Any and Every... (was Re: Eval)



> I think now the terminology gets completely out of hand. :-)
>
> Let's say my language L has the simple types INTEGER and BOOLEAN as
> well as the compound types (well, type-constructors) ARRAY and
> RECORD. The "set of types in L" is {INTEGER, BOOLEAN, ARRAY,
> RECORD} where ARRAY and RECORD stand for "all declared ARRAY and
> RECORD types" (so there are lots).
>
> The subset of simple types of L is {INTEGER, BOOLEAN} and the
> subset of compound types of L is {ARRAY, RECORD}. Now why would I
> *not* be able to talk about the intersection of these to subsets
> being empty? All elements are types, but they are *different* types.

Usually, when you talk about a type as the union of two other types it
usually refers to the values that the type can hold, not the set of type
objects themselves (many languages do not even have first-class type
objects).  Instead this refers to the concept of a type as a set of possible
values, so the "union type" of two types would comprise the possible set of
values of its constituent types.  In your example, the union type of INTEGER
and BOOLEAN is the type that contains the INTEGER and BOOLEAN values.  Thus
under this model, the type union of all types is a type that can hold any
value, while the type intersection of all types most likely can hold no
values.

Of course, the static contract (or interface) of such types is the inverse
operation over the contracts of the constituent types, where the static
contract is what the compiler can deduce about use of instances of that type
at compile time.  For example, if AorB is the union of types A and B, then
the static contract of AorB is the intersection of the contracts of A and B,
so if the only thing in common between A and B is the method 'foo', then
that is the only thing known about an instance of AorB at compile-time is
that it may invoke the method 'foo' on it.  Thus the static contract of a
universal union type is usually quite small, if not empty.  Likewise, the
universal intersection type would satisfy the contract of any type, but
since it cannot have any instances, it is not really useful for much.

Here is where null may cause some confusion.  Many type systems, such as
that of the Java language, allow class variables to contain a null value
even though the 'null' value is not considered to be a member of that class
and does not honor its contract.  Thus the intersection type for all class
types does not actually contain the 'null' value.

In a strict statically typed system, variables with the static any type are
useful for containing arbitrary values but do not allow many useful
operations without a runtime cast.  In Curl, we treat the 'any' type
specially and disable compile-time checking for variables of type 'any',
which gives you dynamic typing; you can also turn this behavior off with
compiler directives.

- Christopher