2.6 The Any DomainΒΆ

With the exception of objects of type Record, all FriCAS data structures are homogenous, that is, they hold objects all of the same type. 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"]
\[\mathrm{[1,7.2,32,x2,"wally"]}\]

Type: List Any

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

u.1
\[1\]

Type: PositiveInteger

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

u.3
\[\frac{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)

Warning

Matrix Any is not a valid type.

Perhaps you are wondering how FriCAS 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.