type
type-checking function
Calling Sequence
Parameters
Description
Details
Defined Types
Examples
type(e, t)
e
-
expression
t
valid type expression
In many contexts, it is not necessary to know the exact value of an expression; it suffices to know that an expression belongs to some broad class, or group, of expressions that share some common properties. These classes or groups are known as types. If T represents a type, then an expression is of type T if it belongs to the class that T represents. For example, an expression is said to be of type posint if it belongs to the class of expressions denoted by the type name posint, which is the set of positive integers.
Many Maple procedures use types to direct the flow of control in algorithms or to decide whether an expression is a valid input. The behavior of the non-commutative multiplication operator `.` depends on the type of its arguments.
Many of these types (classes) have names, such as integer, numeric, list, and radalgnum. Other types are described by forming more complicated type expressions, built up via a grammar (a set of rules for their valid combination) from more primitive type expressions. For more information, see type/structure. The class of expressions that represent valid types is itself described by a type called type. (That is, type(T, type) returns true only when T is a valid type expression. In particular, type(type, type) returns true.)
Types can represent expressions that share a common underlying data structure, such as the types list and table, or can represent mathematical properties, such as type prime.
The type(e, t) calling sequence allows you to test whether a Maple expression is of a given type. The call type(e, t) returns the value true if the expression e is of type t, and returns the value false otherwise.
Note: The type function does not check assumptions, it only considers the object itself. If you are using the assume facility, it is recommended that you use the is function.
Two arguments must be passed to type. The first argument can be any Maple expression. The second argument must be a valid type expression. A type expression may be as simple as a name that is known to type, but it may also be an arbitrarily complicated structured type (see type/structure). It is assumed that the first argument is NULL in a flattened expression when only one argument is received by a call to type.
An exception is raised only in the case that the second argument t is not a valid type.
Expressions of the form e::t are also used to perform type tests in certain contexts. When evaluated in a Boolean context (such as the test expression in an if statement), the expression e::t evaluates to true if e is of type t, and evaluates to false otherwise. It is used, primarily, for automatically checking the types of arguments passed to procedures. For more information, see typematch.
Types (or type expressions) can be categorized according to the way in which they are defined in Maple.
The simplest types are the surface types. These are generally defined in the Maple kernel, and represent superficial or top-level properties of expressions. For example, type list is a surface type. Testing against a surface type is very fast; surface type tests can be completed in constant time, regardless of the size of the expression being tested. For more information, see type/surface.
Arbitrarily complicated structured types can be formed by combining simpler, more primitive types. They allow you to classify expressions based on their deep structure. For example, the type expression list⁡posint represents the class of lists whose members are positive integers. Testing against this type requires not only that the top-level data type (list) of the expression be tested, but also that each list member be examined to determine whether it has the correct type (posint). Testing an expression against a structured type may require a full, recursive traversal of the expression, so the time required to perform a structured type test often increases with the size of the expression. For more information on structured type expressions, see type/structure.
Defined types are named types that may perform arbitrary computation. A type named T is defined by assigning to the global name `type/T` a structured type expression or a procedure. There is no rule of thumb for the performance characteristics of defined types, since they may be very simple or arbitrarily complex. For more information on defining types, see type/definition.
The following type names, which include surface and structured types, are defined in Maple:
!
*
+
.
::
<
<=
<>
=
@
@@
^
_Inert
abstract_rootof
ac_var
algebraic
AlgebraicObject
algext
algfun
algnum
algnumext
And
and
anticommutative
anyfunc
anyindex
anything
appliable
applied
arctrig
arctrigh
arithop
array
Array
assignable
atomic
attributed
boolean
boolean_function
BooleanOpt
builtin
ByteArray
cache
callable
character
Clock
ClosedIdeal
CommAlgebra
commutative
complex
complexcons
composition
const
constant
copyrighted
cubefree
cubic
cx_infinity
cx_zero
DataFrame
DataSeries
Date
DeepLearning:-Tensor
dependent
dictionary
dimension
disjcyc
double
embedded_axis
embedded_imaginary
embedded_real
equation
equationlist
even
evenfunc
evenodd
expanded
extended_numeric
extended_rational
facint
factorial
filedesc
filename
finite
float
float[8]
float[]
foreign
form
fraction
freeof
function
global
hfarray
hfloat
identical
imaginary
implies
in
indexable
indexed
indexedfun
infinity
integer
intersect
last_name_eval
laurent
linear
list
listlist
literal
local
logical
maple
mathfunc
Matrix
matrix
MatrixPolynomialObject
minus
module
moduledefinition
monomial
MonomialOrder
mutable
MVIndex
name
nc_var
neg_infinity
negative
negint
negzero
nested
Non
noncommutative
nonemptylist
nonemptyset
nonemptystring
nonnegative
nonnegint
nonposint
nonpositive
nonreal
Not
not
nothing
numeric
object
odd
oddfunc
operator
Or
or
OreAlgebra
package
partition
patfunc
patindex
patlist
permlist
piecewise
Point
point
polynom
PolynomialIdeal
pos_infinity
posint
positive
posneg
poszero
prime
primepower
procedure
property
protected
python
quadratic
quartic
Queue
radalgfun
radalgnum
radext
radfun
radfunext
radical
radnum
radnumext
Range
range
rational
ratpoly
ratseq
real_infinity
realcons
record
relation
RootOf
rtable
satisfies
scalar
SDMPolynom
sequential
SERIES
series
set
sfloat
ShortMonomialOrder
ShortTermOrder
SkewAlgebra
SkewParamAlgebra
SkewPolynomial
specfunc
specified_rootof
specindex
sqrt
squarefree
Stack
stack(deprecated)
std
stdlib
string
structure
subset
suffixed
surface
symbol
SymbolicInfinity
symmfunc
syntactically_valid_compound_unit
syntactically_valid_unit_name
table
tabular
taylor
Temperature
TermOrder(deprecated)
TEXT
Time
trig
trigh
truefalse
truefalseFAIL
typefunc
typeindex
undefined
uneval
union
Vector
vector
VectorSpace
verification
verify
with_unit
xor
zppoly
||
Notes:
If a type name is an operator or keyword, it must be enclosed in left single quotes to prevent a syntax error. See the examples below.
Some types become active only after a specific package is loaded. For example, the type/const is active after the difforms package is loaded.
For extending the list above by embedding arbitrary predicates in the Maple type system, see type/satisfies. For more information on specific types, see type/datatype, where datatype is one of the names in the list above.
Arguments passed to the type command are evaluated normally as for other Maple commands. While it is rarely necessary to do so in interactive use, Maple programs that seek to be robust should enclose names that appear in type expressions with unevaluation quotes (') to prevent evaluation. For example, if the name T is assigned the value 2 and is also used as a type name, then type(e, 'T') will work correctly, while type(e, T) will likely fail. (In this case, it would fail silently, because 2 is a valid type expression.) See the examples below.
In Maple, type expressions are first class expressions. Types can be passed as arguments to, and returned from, procedures and can be stored in data structures. You can manipulate complicated type expressions just as you would any other Maple expression. Type expressions are, in fact, ordinary Maple expressions. It is only in certain contexts that these expressions are recognized as types. (Not all expressions are valid types, however.)
Note: There is no exprseq type in Maple. However, the whattype function returns exprseq for objects that are expression sequences. (There is no Maple object o for which type( o, exprseq ) returns true. In fact, it is not possible to construct a call to type with an expression sequence as its first argument, because expression sequences are flattened.)
You can make a data type known to the type function in the following way. If you have defined the procedure `type/mytype`, then a call to type of the form: type(a, mytype(b, c, ...)) evaluates the function call `type/mytype`(a, b, c,...).
A number of Maple commands other than type are designed to work with type expressions. See, for example, hastype, anames, and indets. Other commands, such as select, work well with the type command, though they are designed to work with more general predicates.
type⁡6.777800,float
true
type⁡6.777800,rational
false
whattype⁡solve⁡3⁢x+5=14,x
type⁡sin⁡x,trig
type⁡a+b,polynom
type⁡23,a⁢x−b⁢y,rational,polynom
For symbols and reserved names, use name quotes.
type⁡a+b,`+`
type⁡a⁢b,`+`
type⁡aandb,`and`
type⁡module_export⁡eend module,'`module`'
a,b,5
whattype⁡
exprseq
whattype⁡NULL
type⁡NULL,exprseq
type⁡exprseq,NULL
type⁡a,b,c,list
False negative test.
`type/T`≔list:
T≔2:
type⁡a,b,c,T
The next two commands are correct.
type⁡2,T
False positive test.
See Also
convert
define
ExtendingMaple
hastype
is
quotes
subtype
type/definition
type/structure
type/surface
type/type
TypeTools
whattype
Download Help Document