]>
Book Contents Previous Section 2.5 Unions Next Section 2.7 Conversion Book Index

## 2.6 The ``Any'' Domain

With the exception of objects of type Record, all Axiom data structures are homogenous, that is, they hold objects all of the same type. Any If you need to get around this, you can use type Any. Using Any, for example, you can create lists whose elements are integers, rational numbers, strings, and even other lists.

Declare u to have type Any.

u: Any
Type: Void

Assign a list of mixed type values to u

u := [1, 7.2, 3/2, x**2, "wally"]

[1,7.2,3 2,x 2,"wally"]

Type: List Any

When we ask for the elements, Axiom displays these types.

u.1

1

Type: PositiveInteger

Actually, these objects belong to Any but Axiom automatically converts them to their natural types for you.

u.3

3 2

Type: Fraction Integer

Since type Any can be anything, it can only belong to type Type. Therefore it cannot be used in algebraic domains.

v : Matrix(Any)
Matrix Any is not a valid type.

Perhaps you are wondering how Axiom internally represents objects of type Any. An object of type Any consists not only of a data part representing its normal value, but also a type part (a badge) giving badge its type. For example, the value 1 of type PositiveInteger as an object of type Any internally looks like [1,PositiveInteger()].

When should you use Any instead of a Union type? For a Union, you must know in advance exactly which types you are going to allow. For Any, anything that comes along can be accommodated.

Book Contents Previous Section 2.5 Unions Next Section 2.7 Conversion Book Index