type
Returns the type of an object.
Syntax
-
type(X)
-
X
is any object
-
Description
If X
is any object, then type(X)
returns, as a string, the name of the type of X
.
Notes
The class
function is very similar to type
.
While type
gives the datatype of an object, class
gives the class of it. Although for most objects, the type equals the class, the class concept is a slightly coarser classification. The class of an objects describes its under-the-hood implementation and in some cases two objects can be of the same class but still be of different types.
The main example concerns structures. structure
is a class which can be used for any structure. Some structures, however, have a fixed set of keys. Examples of such “typed structures” are date and time structures. These belong to a specific class named typed structure
. But their types describe their named key set. Consequently, while both date()
and time()
have typed structure
as their class, their types are structure of type "Date"
and structure of type "Time"
, respectively.
Examples
'( 1, 1/2, π, i, "nargle", true, sin, (n ↦ n^2 + 1), color("red"), ZeroVector(3), IdentityMatrix(10), '(1, 2), {1, 2}, date(), ColorGradient(100, 100, "red", "gold"), SineTone(400, 0.1, 1) ) @ type
integer rational number real number complex number string boolean kernel function custom function color real vector real matrix array set structure of type "Date" pixmap sound