Definition of a Structured Type in Maple
Description
Examples
A structured type is a Maple expression other than a symbol that can be interpreted as a type. A typical example would be set(name=algebraic). This specifies a set of equations whose left-hand sides are (variable) names, and whose right-hand sides are of type algebraic.
This file first gives a formal grammatical description of the valid structured types, then provides notes on some of the special types, and lastly gives examples.
In the formal definition below, read "::=" to mean "is defined to be", "|" to mean "or", and "*" to mean "zero or more occurrences of".
Syntax
Matches
type ::=
{ type* }
alternation; any of the types
| [ type* ]
a list of the given types
| complex(numeric)
match a complex numerical constant exactly
| string
match a string exactly
| symbol
a system, procedural, or assigned type
| type = type
an equation of the corresponding types
| type <> type
an inequality of the corresponding types
| type < type
a relation of the corresponding types
| type <= type
| type > type
| type >= type
| type .. type
a range of the corresponding types
| type and type
an AND of the corresponding types
| type or type
an OR of the corresponding types
| not type
a NOT of the corresponding type
| type &+ type ...
a sum of the corresponding types
| type &* type ...
a product of the corresponding types
| type ^ type
a power of the corresponding types
| type || type
a concatenation of the corresponding types
| 'type'
an unevaluated expression of the given type
| fcntype
a function or a special type
| name[type*]
an indexed reference of the given types
fcntype ::=
set(type)
a set of elements of the given type
| list(type)
a list of elements of the given type
| Or(type*)
any of the given types
| And(type*)
all of the given types
| Not(type)
not the given type
| identical(expr)
an expression identical to expr
| specfunc(f)
the function f with (possibly zero) arguments of any type
| specfunc(type,f)
the function f with (possibly zero) type arguments
| anyfunc(type*)
any function with arguments of the given types
| specop(operator)
an operator or function expression with operands of any type
| specop(type,operator)
an operator or function expression with type operands
| anyop(type*)
any operator or function with arguments of the given types
| thistype(type)
equivalent to the given type
| typefunc(type0)
a function of type type0 with arguments of any type
| typefunc(type,type0)
a function of type type0 with type arguments
| patfunc(type*,type)
a function with consecutive arguments matching the given type(s). If there are more arguments than types given, all remaining arguments match the last type.
| patfunc[reverse](type,type*)
a function with consecutive arguments matching the given type(s). If there are more arguments than types given, all preceding arguments match the first type.
| specindex(x)
the expression x with indices of any type
| specindex(type,x)
the expression x with all indices of the given type
| typeindex(type0)
an expression of type type0 with indices of any type
| typeindex(type,type0)
an expression of type type0 with all indices of the given type
| anyindex(type*)
any indexed expression with indices of the given types
| patindex(type*,type)
an indexed expression with consecutive indices matching the given type(s). If there are more indices than types given, all remaining indices match the last type.
| patindex[reverse](type,type*)
an indexed expression with consecutive indices matching the given type(s). If there are more indices than types given, all preceding arguments match the first type.
| function(type)
any function with type arguments
| name(type)
any name with a value of the given type
| patlist(type*,type)
a list matching the first type argument(s), with all remaining arguments matching the last type
| patlist[reverse](type,type*)
a list matching the last type argument(s), with all preceding arguments matching the first type
| p(anything*)
type defined by a procedure `type/p`
| f(type*)
the function f of the given types
| `+`(type)
a sum of terms of the given type
| `*`(type)
a product of factors of the given type
| `&+`(type*)
a sum of terms in which the nth term is of the nth type specified in type*
| `&*`(type*)
a product of factors in which the nth factor is of the nth type specified in type*
| type &under func
an expression expr so that func(expr) is of type type
| type &under (func, arg1, arg2)
an expression expr so that func(expr, arg1, arg2) is of type type
Square brackets [] are used to check for a fixed argument sequence. The type [name, set] matches a list with exactly two arguments: a name followed by a set.
Set brackets {} are used for alternation. The type {set(name), list(integer)} matches either a set of names, or a list of integers.
The type anything matches any expression except a sequence.
The type identical(expr) matches the expression expr identically. If there is more than one expr (i.e. identical(expr1,expr2,...)), then this type matches any one of the exprN identically. The type identical() matches the empty expression sequence.
The type anyfunc(t1, ..., tn) matches any function with n arguments of type t1,...,tn. Thus, type(f, anyfunc(t1,...,tn)) is equivalent to the logical conjunction type(f, function) and type([op(f)], [t1,...,tn]).
The type patfunc(t1,..., tn, t) matches any function with n or more arguments where the first n are of type t1,...,tn, and the remaining arguments are of type t.
The type patfunc[reverse](t,t1,...,tn) matches any function with n or more arguments where the last n are of type t1,...,tn, and the preceding arguments are of type t.
The type specfunc(t, n) matches the function n with 0 or more arguments of type t. Thus, type(f, specfunc(t, n)) is equivalent to the logical conjunction type(f, function) and op(0,f) = n and type([op(f)], list(t)). Instead of a single name n, a set of names may be passed as the second parameter to the specfunc type constructor. In this case, an expression matches if it is a function call with any of the names in the set as the 0-th operand. Thus, type(f,specfunc(t,{n1,n2,...,nk})) is equivalent to type(f,specfunc(t,n1)) or type(f,specfunc(t, n2)) or ... or type(f,specfunc(t,nk)).
The type specop(t, n) matches an operator expression or function with zeroth operand n and operands of type t. It is similar to the specfunc type constructor, but also matches expressions, for example, sums, products, and relations, as well as functions. As for the specfunc type constructor, the second parameter may be a set of names rather than just a single name.
The type typefunc(t, T) matches a function of type T with 0 or more arguments of type t. Thus, type(f, typefunc(t, T)) is equivalent to the logical conjunction type(f, function) and type([op(0,f)], [T]) and type([op(f)], list(t)).
Analogous to specfunc, anyfunc, typefunc, patfunc, and patfunc[reverse], the type constructors specindex, anyindex, typeindex, patindex, and patindex[reverse] can be used to test for expressions with indices of prescribed types and the type constructors patlist and patlist[reverse] can be used to test for lists with elements of prescribed types.
The type type &under func describes expressions expr for which func(expr) is of type type. The second form of this type takes an arbitrary number of extra arguments for func; in particular, type &under (func, arg1, arg2, ...) describes expressions expr for which func(expr, arg1, arg2, ...) is of type type.
The type thistype(t) matches an expression of type t. Its primary use is to define types where t is used more than once, such as {thistype,set}(t), which is equivalent to {t,set(t)}.
type⁡string,string
false
type⁡string,identical⁡string
true
type⁡x−2,nameinteger
type⁡x−2,nameposint
type⁡x−2,algebraicinteger
type⁡x+y12+1,`&+`⁡name,radical,integer
type⁡a⁢b⁢c,`&*`⁡algebraic,algebraic,algebraic
type⁡exp⁡x,exp⁡name
T≔TEXT⁡line 1,line 2:
type⁡T,TEXT⁡string
type⁡T,TEXT⁡string,string
type⁡T,specfunc⁡string,TEXT
type⁡T,anyfunc⁡string
type⁡T,anyfunc⁡string,string
type⁡T,typefunc⁡string,symbol
type⁡T,function⁡string
type⁡F⁡a,b,specop⁡anything,F
type⁡a+b,specfunc⁡anything,`+`
type⁡a+b,specop⁡anything,`+`
type⁡a+b,specop⁡anything,`*`,`+`
type⁡f⁡a,1,2,patfunc⁡name,posint
type⁡f⁡a,b,1,patfunc⁡name,posint
type⁡f⁡a,b,1,patfuncreverse⁡name,posint
type⁡x,1,name,integer
type⁡x,1,list⁡integer
type⁡x,1,list⁡name
type⁡x,1,list⁡integer,name
type⁡T,name⁡TEXT⁡string,string
type⁡ab,specindex⁡anything,a
type⁡ab,specindex⁡integer,a
type⁡a2,specindex⁡integer,a
type⁡a2,a string,anyindex⁡integer,string
type⁡a2,a string,anyindex⁡string,integer
type⁡a2,typeindex⁡integer,symbol
Test for angles that have a rational cosine.
type⁡π3,rational&undercos
type⁡π4,rational&undercos
Test for an arbitrary data structure containing positive integers.
type⁡2,3,4,`&under`⁡list⁡posint,convert,list
type⁡1,2|3,52,`&under`⁡list⁡posint,convert,list
See Also
type
type/literal
type/surface
Download Help Document